forked from arnav-kr/slcodepreview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
51 lines (50 loc) · 1.57 KB
/
service-worker.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
self.skipWaiting();
self.addEventListener('push', function(ev) {
console.log('[Service Worker] Received a push message\n');
let payload = ev.data.json()
console.log(payload)
if (payload.notification && payload.notification.title) {
self.registration.showNotification(payload.notification.title, {
body: payload.notification.body,
icon: 'arnav.png',
badge: 'arnav.png',
image: payload.notification.image,
data: payload.data
})
} else {
console.log('[Service Worker] No notification payload, not showing notification')
}
});
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('slcodepreview').then(function(cache) {
return cache.addAll([
'./',
'https://cdn.jsdelivr.net/gh/AssassinAguilar/Alertism/dist/V1.0.0/main.js',
'index.html',
'res/images/maskable/icon_192.png',
'res/images/maskable/icon_512.png',
'res/images/maskable/icon_384.png',
'res/images/maskable/icon_128.png',
'res/images/maskable/icon_96.png',
'res/images/maskable/icon_72.png',
'res/images/maskable/icon_48.png',
'res/images/maskable/icon.png',
'res/images/icon-192x192.png',
'res/images/icon-256x256.png',
'res/images/icon-384x384.png',
'res/images/icon-512x512.png',
'res/css/style.css',
'res/js/script.js'
]);
})
);
});
self.addEventListener('fetch', function(e) {
console.log(e.request.url);
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});