aboutsummaryrefslogtreecommitdiff
path: root/src/sw.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2023-10-26 15:42:21 +0300
committerHenry Jameson <me@hjkos.com>2023-10-26 15:42:21 +0300
commit0628aac664be4ccce361d319fad201c44d9257fe (patch)
treebd59c87ca770b9da97bef6e589064a03f0ddc01b /src/sw.js
parent1b7e930b2e850408f46876395a85628b05729cc9 (diff)
fallback to old notification method, don't spam if old way of creating
notification fails, try to use favicon
Diffstat (limited to 'src/sw.js')
-rw-r--r--src/sw.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/sw.js b/src/sw.js
index 1889d15f..1b08fe69 100644
--- a/src/sw.js
+++ b/src/sw.js
@@ -59,16 +59,19 @@ self.addEventListener('message', async (event) => {
console.log(event)
if (type === 'desktopNotification') {
- const { title, body, icon, id } = content
- if (state.notificationIds.has(id)) return
- state.notificationIds.add(id)
- setTimeout(() => state.notificationIds.delete(id), 10000)
- self.registration.showNotification('SWTEST: ' + title, { body, icon })
+ const { title, ...rest } = content
+ const { tag } = rest
+ if (state.notificationIds.has(tag)) return
+ state.notificationIds.add(tag)
+ setTimeout(() => state.notificationIds.delete(tag), 10000)
+ self.registration.showNotification(title, rest)
}
if (type === 'updateFocus') {
state.lastFocused = event.source.id
- console.log(state)
+
+ const notifications = await self.registration.getNotifications()
+ notifications.forEach(n => n.close())
}
})