diff options
-rw-r--r-- | modern/src/index.jsx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modern/src/index.jsx b/modern/src/index.jsx index 3eb96d2f..33524e97 100644 --- a/modern/src/index.jsx +++ b/modern/src/index.jsx @@ -16,6 +16,33 @@ import NativeInterface from './common/components/NativeInterface'; import ServerProvider from './ServerProvider'; import ErrorBoundary from './ErrorBoundary'; import AppThemeProvider from './AppThemeProvider'; +import { registerSW } from 'virtual:pwa-register' + +const ServiceWorkerUpdateCheckInterval = 60 * 60 * 1000; + +registerSW({ + onRegisteredSW(swUrl, r) { + r && setInterval(async () => { + if (!(!r.installing && navigator)) + return + + if (('connection' in navigator) && !navigator.onLine) + return + + const resp = await fetch(swUrl, { + cache: 'no-store', + headers: { + 'cache': 'no-store', + 'cache-control': 'no-cache', + }, + }) + + if (resp?.status === 200) + await r.update() + }, ServiceWorkerUpdateCheckInterval) + }, + immediate: true +}); preloadImages(); |