feat: add pwa update prompt

This commit is contained in:
Xyphyn committed 2023-08-03 10:57:13 -07:00
1 parent 5582e49be9
commit b94e294dfb
3 files changed
+46 -17

No files matched your search

+9 -16
View File
@@ -10,6 +10,7 @@
import { onMount } from 'svelte'
// @ts-ignore
import { pwaInfo } from 'virtual:pwa-info'
import PwaReload from '$lib/PwaReload.svelte'
nProgress.configure({
minimum: 0.4,
@@ -32,25 +33,13 @@
}
}
onMount(async () => {
if (pwaInfo) {
const { registerSW } = await import('virtual:pwa-register')
registerSW({
immediate: true,
onRegistered(r) {
console.log(`SW Registered: ${r}`)
r?.update()
},
onRegisterError(error) {
console.log('SW registration error', error)
},
})
}
})
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
</script>
<svelte:head>
{@html webManifest}
</svelte:head>
<div class="flex flex-col min-h-screen">
<Navbar />
<ToastContainer />
@@ -68,3 +57,7 @@
</main>
</div>
</div>
{#await import('$lib/PwaReload.svelte') then { default: PwaReload }}
<PwaReload />
{/await}