|
@ -112,6 +112,25 @@ self.addEventListener("message", (event) => { |
|
|
logConsoleAndDb("Service worker posted a message."); |
|
|
logConsoleAndDb("Service worker posted a message."); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener("notificationclick", (event) => { |
|
|
|
|
|
logConsoleAndDb("Notification got clicked.", event); |
|
|
|
|
|
event.notification.close(); |
|
|
|
|
|
// from https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event
|
|
|
|
|
|
// ... though I don't see any benefit over just "clients.openWindow"
|
|
|
|
|
|
event.waitUntil( |
|
|
|
|
|
clients |
|
|
|
|
|
.matchAll({ |
|
|
|
|
|
type: "window", |
|
|
|
|
|
}) |
|
|
|
|
|
.then((clientList) => { |
|
|
|
|
|
for (const client of clientList) { |
|
|
|
|
|
if (client.url === "/" && "focus" in client) return client.focus(); |
|
|
|
|
|
} |
|
|
|
|
|
if (clients.openWindow) return clients.openWindow("/"); |
|
|
|
|
|
}), |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
self.addEventListener("fetch", (event) => { |
|
|
self.addEventListener("fetch", (event) => { |
|
|
logConsoleAndDb("Service worker got fetch event.", event); |
|
|
logConsoleAndDb("Service worker got fetch event.", event); |
|
|
}); |
|
|
}); |
|
|