fix: service worker registration
This commit is contained in:
1
web/src/app.d.ts
vendored
1
web/src/app.d.ts
vendored
@@ -1,3 +1,4 @@
|
||||
/// <reference types="vite-plugin-pwa/client" />
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { pwaInfo } from 'virtual:pwa-info';
|
||||
import { page } from '$app/state';
|
||||
import { hasToken } from '$lib/api/client';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
@@ -8,7 +9,15 @@
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
onMount(() => {
|
||||
onMount(async () => {
|
||||
// Register the PWA service worker through SvelteKit's pipeline.
|
||||
// vite-plugin-pwa's injectRegister option cannot inject into SvelteKit's
|
||||
// HTML because SvelteKit intercepts Vite's transformIndexHtml hook.
|
||||
if (pwaInfo) {
|
||||
const { registerSW } = await import('virtual:pwa-register');
|
||||
registerSW({ immediate: true });
|
||||
}
|
||||
|
||||
if (!hasToken() && page.url.pathname !== '/settings') {
|
||||
goto('/settings');
|
||||
}
|
||||
@@ -46,6 +55,12 @@
|
||||
onDestroy(() => clearInterval(tickInterval));
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
{#if pwaInfo}
|
||||
{@html pwaInfo.webManifest.linkTag}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
<nav>
|
||||
<div class="nav-links">
|
||||
<a href={todayHref()} class:active={todayActive}>Today</a>
|
||||
|
||||
Reference in New Issue
Block a user