implement notification click
This commit is contained in:
18
web/sw.js
18
web/sw.js
@@ -8,10 +8,26 @@ self.addEventListener('activate', function (event) {
|
||||
|
||||
self.addEventListener("push", (event) => {
|
||||
if (event.data) {
|
||||
const { summary, location } = event.data.json()
|
||||
event.waitUntil(
|
||||
self.registration.showNotification("7am weather summary", {
|
||||
body: event.data.text()
|
||||
data: location,
|
||||
body: summary,
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close()
|
||||
event.waitUntil(
|
||||
self.clients.matchAll({ type: "window" })
|
||||
.then((clientList) => {
|
||||
const loc = event.notification.data
|
||||
for (const client of clientList) {
|
||||
if (client.url === `/${loc}` && "focus" in client) return client.focus();
|
||||
}
|
||||
if (self.clients.openWindow) return self.clients.openWindow(`/${loc}`);
|
||||
})
|
||||
)
|
||||
})
|
||||
|
Reference in New Issue
Block a user