forked from schn4ck/schnack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
27 lines (22 loc) · 646 Bytes
/
sw.js
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
self.addEventListener('push', (event) => {
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
let data = {};
if (event.data) {
data = event.data.json();
}
const title = data.title;
const message = data.message;
self.clickTarget = data.clickTarget;
event.waitUntil(self.registration.showNotification(title, {
body: message,
tag: 'schnack'
}));
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
if(clients.openWindow){
event.waitUntil(clients.openWindow(self.clickTarget));
}
});