diff options
| author | Fuwn <[email protected]> | 2024-07-25 04:19:44 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-25 04:19:44 -0700 |
| commit | c49056e057b590002c2cdb59011d9be101651c72 (patch) | |
| tree | 6be6c92d0aec4755a9292315a6553f746d823bc8 | |
| parent | fix(service-worker): wrap push in waitUntil (diff) | |
| download | due.moe-c49056e057b590002c2cdb59011d9be101651c72.tar.xz due.moe-c49056e057b590002c2cdb59011d9be101651c72.zip | |
fix(service-worker): properly await all promises
| -rw-r--r-- | src/service-worker.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/service-worker.ts b/src/service-worker.ts index 4799a492..18c839b1 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -114,8 +114,7 @@ sw.addEventListener('push', async (event: PushEvent) => { new Date().getTime()) ) { await database.users.update(user.id, { lastNotificationID: recentNotifications[0].id }); - - sw.registration.showNotification('due.moe', { + await sw.registration.showNotification('due.moe', { body: `${recentNotifications[0].user.name}${recentNotifications[0].context}`, icon: recentNotifications[0].user.avatar.large || '/favicon-196x196.png', // Ref. https://stackoverflow.com/a/50805868/14452787 @@ -129,18 +128,18 @@ sw.addEventListener('push', async (event: PushEvent) => { } if (navigator.userAgent.includes('Chrome')) { - sw.registration.showNotification('due.moe', { + await sw.registration.showNotification('due.moe', { body: 'No new notifications', icon: '/favicon-196x196.png', tag: 'notification-1' }); // Ref. https://github.com/firebase/quickstart-js/issues/126#issuecomment-504081087 - new Promise((resolve) => { + await new Promise((resolve) => { (resolve as unknown as () => void)(); setTimeout( - () => - sw.registration + async () => + await sw.registration .getNotifications() .then((notifications) => notifications.forEach((notification) => notification.close()) |