Handle PWA update correctly

This commit is contained in:
2025-09-07 03:44:45 +02:00
parent 12635511af
commit 114be9c71f
5 changed files with 44 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
// @ts-expect-error weird import
import { useRegisterSW } from 'virtual:pwa-register/vue';
import { useToast } from 'vuestic-ui';
export function usePWAReload() {
const { init } = useToast();
const { updateServiceWorker } = useRegisterSW({
immediate: true,
onRegisteredSW: (_: string, r: ServiceWorkerRegistration) => {
if (import.meta.env.PROD && r) {
setInterval(
async () => {
await r.update();
},
5 * 60 * 1000
);
}
},
onOfflineReady: () =>
init({
title: 'Offline Verfügbar',
message: 'Diese WebApp ist nun offline verfügbar!',
color: 'success',
duration: 2000
}),
onNeedRefresh: () =>
init({
title: 'Update verfügbar',
message: 'Für diese WebApp ist ein Update verfügbar, bitte klicke hier zum Aktualisieren!',
color: 'warning',
duration: 0,
closeable: false,
onClick: updateServiceWorker
})
});
}