From e1e3a244cd2942faf0af8bd2110853acd50639fb Mon Sep 17 00:00:00 2001 From: Soxasora Date: Mon, 6 Jan 2025 20:10:08 +0100 Subject: [PATCH] align CLEAR_NOTIFICATIONS promises to event.waitUntil --- sw/eventListener.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sw/eventListener.js b/sw/eventListener.js index 1dfc39e56..4f63641f2 100644 --- a/sw/eventListener.js +++ b/sw/eventListener.js @@ -242,17 +242,13 @@ export function onMessage (sw) { return event.waitUntil(storage.removeItem('subscription')) } if (event.data.action === CLEAR_NOTIFICATIONS) { - return event.waitUntil((async () => { - let notifications = [] - try { - notifications = await sw.registration.getNotifications() - } catch (err) { - console.error('failed to get notifications') - } + const promises = [] + promises.push(sw.registration.getNotifications().then((notifications) => { notifications.forEach(notification => notification.close()) - activeCount = 0 - return await clearAppBadge(sw) - })()) + })) + activeCount = 0 + promises.push(clearAppBadge(sw)) + event.waitUntil(Promise.all(promises)) } } }