Skip to content

Commit

Permalink
align CLEAR_NOTIFICATIONS promises to event.waitUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Jan 6, 2025
1 parent 432b436 commit e1e3a24
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions sw/eventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

0 comments on commit e1e3a24

Please sign in to comment.