-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
39 lines (33 loc) · 1009 Bytes
/
Copy pathsw.js
File metadata and controls
39 lines (33 loc) · 1009 Bytes
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
33
34
35
36
37
38
39
// Install event - cache assets if needed
self.addEventListener('install', event => {
console.log('Service Worker installing.');
// Skip waiting to activate immediately
self.skipWaiting();
});
// Activate event - claim clients
self.addEventListener('activate', event => {
console.log('Service Worker activating.');
event.waitUntil(clients.claim());
});
self.addEventListener('push', event => {
if (!event.data) return;
const data = event.data.json();
const options = {
body: data.body,
icon: data.icon || '/icon-192.png',
badge: data.badge || '/badge-72.png',
vibrate: [200, 100, 200],
tag: 'validator-duty',
requireInteraction: true,
data: data.data
};
event.waitUntil(
self.registration.showNotification(data.title, options)
);
});
self.addEventListener('notificationclick', event => {
event.notification.close();
event.waitUntil(
clients.openWindow('/')
);
});