This commit is contained in:
parent
7d8f59dec7
commit
10fa4522ba
1 changed files with 8 additions and 3 deletions
|
@ -1,25 +1,30 @@
|
||||||
<script>
|
<script>
|
||||||
import BottomAppBar from '$lib/components/BottomAppBar.svelte';
|
import BottomAppBar from '$lib/components/BottomAppBar.svelte';
|
||||||
|
import Toast from '$lib/components/Toast.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let node;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
addEventListener('load', function () {
|
addEventListener('load', function () {
|
||||||
navigator.serviceWorker.register('/service-worker.js');
|
navigator.serviceWorker.register('/service-worker.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
navigator.serviceWorker.addEventListener('message', (event) => {
|
const channel = new BroadcastChannel('sw-messages');
|
||||||
console.log(`The service worker sent me a message: ${event.data}`);
|
channel.addEventListener('message', (event) => {
|
||||||
alert('You can use the app offline');
|
new Toast({ target: node });
|
||||||
});
|
});
|
||||||
|
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
navigator.serviceWorker.ready.then((registration) => {
|
||||||
|
console.log(registration);
|
||||||
console.log('registered service worker');
|
console.log('registered service worker');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={node}></div>
|
||||||
<slot />
|
<slot />
|
||||||
<footer>
|
<footer>
|
||||||
<BottomAppBar />
|
<BottomAppBar />
|
||||||
|
|
Loading…
Reference in a new issue