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