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,6 +1,8 @@
<script> <script>
import BottomAppBar from '$lib/components/BottomAppBar.svelte'; import BottomAppBar from '$lib/components/BottomAppBar.svelte';
import { onMount } from 'svelte';
onMount(() => {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
addEventListener('load', function () { addEventListener('load', function () {
navigator.serviceWorker.register('../sw.ts'); navigator.serviceWorker.register('../sw.ts');
@ -8,13 +10,14 @@
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 />