Updates on sw.js registering
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
Alessio Davoli 2023-07-19 20:08:53 +02:00
parent c5cca78b1c
commit 551fe07d0e
4 changed files with 21 additions and 9 deletions

View file

@ -1,8 +1,23 @@
<script> <script>
import BottomAppBar from '$lib/components/BottomAppBar.svelte'; import BottomAppBar from '$lib/components/BottomAppBar.svelte';
</script>
<slot></slot> 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.ready.then((registration) => {
console.log("registered service worker")
});
}
</script>
<slot />
<footer> <footer>
<BottomAppBar /> <BottomAppBar />
</footer> </footer>

View file

@ -2,13 +2,6 @@
import Header from '$lib/components/Header.svelte'; import Header from '$lib/components/Header.svelte';
import Tabs from '$lib/components/Tabs.svelte'; import Tabs from '$lib/components/Tabs.svelte';
import MapTab from '$lib/components/tabs/MapTab.svelte'; import MapTab from '$lib/components/tabs/MapTab.svelte';
import { onMount } from 'svelte';
let syncWorker: Worker | undefined = undefined;
let latitude;
let longitude;
let accuracy;
export let data; export let data;
let divider; let divider;

View file

@ -32,6 +32,7 @@ self.addEventListener('activate', (event) => {
} }
event.waitUntil(deleteOldCaches()); event.waitUntil(deleteOldCaches());
postMessage("completed");
}); });
self.addEventListener('fetch', (event) => { self.addEventListener('fetch', (event) => {

View file

@ -8,6 +8,9 @@ const config = {
files: { files: {
serviceWorker: 'src/sw.ts', serviceWorker: 'src/sw.ts',
}, },
serviceWorker: {
register: false,
},
adapter: adapter({ adapter: adapter({
fallback: null, fallback: null,
precompress: true, precompress: true,