aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorMatjaž Črnko <m.crnko@txt.si>2023-11-05 19:54:57 +0100
committerMatjaž Črnko <m.crnko@txt.si>2023-11-05 19:54:57 +0100
commit0daf321f1492d6ba9e30ff5bf2ff91e44809374f (patch)
tree5671e15fc6797492d96949db5f885451f406070b /modern
parentd59b39c6aad3863583294dd59b616c34a1fadf35 (diff)
downloadtrackermap-web-0daf321f1492d6ba9e30ff5bf2ff91e44809374f.tar.gz
trackermap-web-0daf321f1492d6ba9e30ff5bf2ff91e44809374f.tar.bz2
trackermap-web-0daf321f1492d6ba9e30ff5bf2ff91e44809374f.zip
fix: PWA regularly check for service worker updates and automaticially reload the app.
Diffstat (limited to 'modern')
-rw-r--r--modern/src/index.jsx27
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();