Back with sw.js

This commit is contained in:
Alessio Davoli 2023-12-12 16:56:43 +01:00
parent bd57812964
commit 9e7bfc5468

View file

@ -1,11 +1,10 @@
<script lang="ts">
import BottomAppBar from '$lib/components/BottomAppBar.svelte';
// import Toast from '$lib/components/Toast.svelte';
// import { onMount } from 'svelte';
import Toast from '$lib/components/Toast.svelte';
import { onMount } from 'svelte';
let node;
let node: HTMLElement;
/**
onMount(() => {
if(import.meta.env.DEV) return;
@ -17,22 +16,19 @@
if (BroadcastChannel) {
const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', (event) => {
console.log(event.data);
new Toast({ target: node });
});
} else {
navigator.serviceWorker.addEventListener('message', (evt) => {
console.log(evt.data);
new Toast({ target: node });
});
}
navigator.serviceWorker.ready.then((registration) => {
registration.active.postMessage('Save client');
registration?.active?.postMessage('Save client');
});
}
});
*/
</script>
<div bind:this={node}></div>