Compare commits

..

No commits in common. "b2347b04663f600816e142c1199bbd7118a676a9" and "bec8fcdce1d385ba77edaa838f4ddf61c29371b1" have entirely different histories.

2 changed files with 9 additions and 28 deletions

View file

@ -4,28 +4,21 @@
import { onMount } from 'svelte';
let node;
onMount(() => {
if ('serviceWorker' in navigator) {
addEventListener('load', function () {
navigator.serviceWorker.register('/service-worker.js');
});
if (BroadcastChannel) {
const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', (event) => {
console.log(event.data);
new Toast({ target: node });
});
} else {
navigator.serviceWorker.addEventListener('message', (evt) => {
console.log(evt.data);
new Toast({ target: node });
});
}
const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', (event) => {
new Toast({ target: node });
});
navigator.serviceWorker.ready.then((registration) => {
registration.active.postMessage('Save client');
console.log(registration);
console.log('registered service worker');
});
}
});

View file

@ -14,12 +14,6 @@ const ASSETS = [
...prerendered // dynamic routes
];
let client;
addEventListener('message', event => {
client = event.source;
});
self.addEventListener('install', (event) => {
// Create a new cache and add all files to it
async function addFilesToCache() {
@ -30,7 +24,7 @@ self.addEventListener('install', (event) => {
event.waitUntil(addFilesToCache());
});
const channel = new BroadcastChannel('sw-messages');
self.addEventListener('activate', (event) => {
@ -42,13 +36,7 @@ self.addEventListener('activate', (event) => {
}
event.waitUntil(deleteOldCaches());
let channel;
if(BroadcastChannel) {
channel = new BroadcastChannel('sw-messages');
channel.postMessage({title: 'Cache Downloaded'});
} else {
client.postMessage("Cache Downloaded")
}
channel.postMessage({title: 'Cache downloaded!'});
});
self.addEventListener('fetch', (event) => {