From c49056e057b590002c2cdb59011d9be101651c72 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 25 Jul 2024 04:19:44 -0700 Subject: fix(service-worker): properly await all promises --- src/service-worker.ts | 11 +++++------ 1 file 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()) -- cgit v1.2.3