service worker fix
This commit is contained in:
parent
34c4e82330
commit
3634076c73
35
sw.js
35
sw.js
@ -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);
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user