feat(webapp): add installable PWA support

This commit is contained in:
2026-03-19 16:40:00 +00:00
parent 65d113046a
commit 22608b80f1
12 changed files with 868 additions and 1 deletions

View File

@@ -1,15 +1,41 @@
<script lang="ts">
// @ts-nocheck
import '../app.css';
import { onMount } from 'svelte';
import { registerSW } from 'virtual:pwa-register';
import favicon from '$lib/assets/favicon.svg';
import { appController } from '$lib/app/controller';
import { clearInstallPrompt, setInstallPrompt, setOfflineReady, setUpdateAvailable } from '$lib/pwa';
let { children } = $props();
onMount(() => {
registerSW({
onNeedRefresh() {
setUpdateAvailable(true);
},
onOfflineReady() {
setOfflineReady(true);
}
});
const handleBeforeInstallPrompt = (event) => {
event.preventDefault();
setInstallPrompt(event);
};
const handleAppInstalled = () => {
clearInstallPrompt();
};
window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
window.addEventListener('appinstalled', handleAppInstalled);
void appController.init();
return () => {
window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
window.removeEventListener('appinstalled', handleAppInstalled);
void appController.destroy();
};
});