fix: service worker registration

This commit is contained in:
2026-05-08 19:23:13 +02:00
parent 68e16fa4ca
commit d3faf79b57
3 changed files with 36 additions and 4 deletions

1
web/src/app.d.ts vendored
View File

@@ -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 {

View File

@@ -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>