aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/lib/svelte/ReloadPrompt.svelte
blob: d54a202111bb81b6e250babe3a098993386a7716 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<script lang="ts">
	import { getToastStore } from "@skeletonlabs/skeleton";
	import { useRegisterSW } from "virtual:pwa-register/svelte";

	const toastStore = getToastStore();

	const  {
		updateServiceWorker,
	} = useRegisterSW({
		onRegisteredSW(r) {
			console.log("SW Registered: ", r)
		},
		onNeedRefresh() {
			toastStore.trigger({
            message: 'A new version of the application is available.',
            autohide: false,
						action: {
							label: 'Refresh',
							response: updateServiceWorker
						}
          });
		},
		onOfflineReady() {
			toastStore.trigger({
            background: 'variant-filled-success',
            message: 'Now ready for offline use!',
            timeout: 5000
          });
		},
		onRegisterError(err) {
			console.error("SW Registration Error: ", err)
		}
	})
</script>