service worker fix

This commit is contained in:
Jonas Weinz 2019-03-21 15:54:06 +01:00
parent 34c4e82330
commit 3634076c73

35
sw.js
View File

@ -1,7 +1,7 @@
self.addEventListener('install', function(e) { self.addEventListener('install', function (e) {
e.waitUntil( e.waitUntil(
caches.open('your-magic-cache').then(function(cache) { caches.open('your-magic-cache').then(function (cache) {
return cache.addAll([ return cache.addAll([
'/website/ultimate_tictactoe/', '/website/ultimate_tictactoe/',
'/website/ultimate_tictactoe/index.html', '/website/ultimate_tictactoe/index.html',
@ -24,36 +24,17 @@ self.addEventListener('install', function(e) {
]); ]);
}) })
); );
}); });
self.addEventListener('fetch', function(event) { self.addEventListener('fetch', function (event) {
event.respondWith( event.respondWith(
caches.match(event.request).then(function(response) { caches.match(event.request).then(function (response) {
return response || fetch(event.request); return response || fetch(event.request);
}) })
); );
}); });
self.addEventListener('notificationclick', function(event) { self.addEventListener('notificationclick', function (event) {
event.waitUntil(async function() { event.notification.close();
const allClients = await clients.matchAll({ clients.openWindow(rel_home);
includeUncontrolled: true
});
var instance = None;
// Let's see if we already have a window open:
for (const client of allClients) {
client.focus();
instance = client;
break;
}
// If we didn't find an existing window,
// open a new one:
if (!instance) {
instance = await clients.openWindow(rel_home);
}
}());
}); });