feat(webapp): add offline shell and iPhone install guidance
This commit is contained in:
@@ -5,7 +5,14 @@
|
||||
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';
|
||||
import {
|
||||
clearInstallPrompt,
|
||||
setInstallPrompt,
|
||||
setOfflineReady,
|
||||
setOnlineStatus,
|
||||
setUpdateAvailable,
|
||||
syncInstallHelpState
|
||||
} from '$lib/pwa';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
@@ -22,20 +29,37 @@
|
||||
const handleBeforeInstallPrompt = (event) => {
|
||||
event.preventDefault();
|
||||
setInstallPrompt(event);
|
||||
syncInstallHelpState();
|
||||
};
|
||||
|
||||
const handleAppInstalled = () => {
|
||||
clearInstallPrompt();
|
||||
syncInstallHelpState();
|
||||
};
|
||||
|
||||
const handleOnline = () => {
|
||||
setOnlineStatus(true);
|
||||
};
|
||||
|
||||
const handleOffline = () => {
|
||||
setOnlineStatus(false);
|
||||
};
|
||||
|
||||
setOnlineStatus(navigator.onLine);
|
||||
syncInstallHelpState();
|
||||
|
||||
window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
|
||||
window.addEventListener('appinstalled', handleAppInstalled);
|
||||
window.addEventListener('online', handleOnline);
|
||||
window.addEventListener('offline', handleOffline);
|
||||
|
||||
void appController.init();
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt);
|
||||
window.removeEventListener('appinstalled', handleAppInstalled);
|
||||
window.removeEventListener('online', handleOnline);
|
||||
window.removeEventListener('offline', handleOffline);
|
||||
void appController.destroy();
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user