From e0eaf961c4749c108d74f5961ed8acdcc911fe0a Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 13 Dec 2023 22:18:28 +0200 Subject: [PATCH] test SHIT --- src/sw.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sw.js b/src/sw.js index 9d1896c77..3e1f99bb8 100644 --- a/src/sw.js +++ b/src/sw.js @@ -59,7 +59,21 @@ const setSettings = async () => { } const showPushNotification = async (event) => { - return self.registration.showNotification(res.title, res) + const activeClients = await getWindowClients() + await setSettings() + // Only show push notifications if all tabs/windows are closed + if (activeClients.length === 0) { + const data = event.data.json() + + const url = `${self.registration.scope}api/v1/notifications/${data.notification_id}` + const notification = await fetch(url, { headers: { Authorization: 'Bearer ' + data.access_token } }) + const notificationJson = await notification.json() + const parsedNotification = parseNotification(notificationJson) + + const res = prepareNotificationObject(parsedNotification, i18n) + + return self.registration.showNotification(res.title, res) + } } self.addEventListener('push', async (event) => {