only onMount
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Alessio Davoli 2023-07-19 20:11:59 +02:00
parent 551fe07d0e
commit 3cd8752fe1

View file

@ -1,20 +1,23 @@
<script> <script>
import BottomAppBar from '$lib/components/BottomAppBar.svelte'; import BottomAppBar from '$lib/components/BottomAppBar.svelte';
import { onMount } from 'svelte';
if ('serviceWorker' in navigator) { onMount(() => {
addEventListener('load', function () { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('../sw.ts'); addEventListener('load', function () {
}); navigator.serviceWorker.register('../sw.ts');
});
navigator.serviceWorker.addEventListener('message', (event) => { navigator.serviceWorker.addEventListener('message', (event) => {
console.log(`The service worker sent me a message: ${event.data}`); console.log(`The service worker sent me a message: ${event.data}`);
alert("You can use the app offline"); alert('You can use the app offline');
}); });
navigator.serviceWorker.ready.then((registration) => { navigator.serviceWorker.ready.then((registration) => {
console.log("registered service worker") console.log('registered service worker');
}); });
} }
});
</script> </script>
<slot /> <slot />