blob: 0402a220503ffb092a348093243bdb40d1a96fc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/* eslint-env serviceworker */
self.addEventListener('push', function (event) {
if (event.data) {
const data = event.data.json()
const promiseChain = clients.matchAll({
includeUncontrolled: true
}).then(function (clientList) {
const list = clientList.filter((item) => item.type === 'window')
if (list.length) return
return self.registration.showNotification(data.title, data)
})
event.waitUntil(promiseChain)
}
})
self.addEventListener('notificationclick', function (event) {
event.notification.close()
event.waitUntil(clients.matchAll({
includeUncontrolled: true
}).then(function (clientList) {
const list = clientList.filter((item) => item.type === 'window')
for (var i = 0; i < list.length; i++) {
var client = list[i]
if (client.url === '/' && 'focus' in client) { return client.focus() }
}
if (clients.openWindow) { return clients.openWindow('/') }
}))
})
|