From 67f042df7534662c289b6f2c53ad0bb6fcfa916e Mon Sep 17 00:00:00 2001 From: rene Date: Sat, 9 May 2026 19:47:14 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20SW-Update=20via=20updatefound+statechang?= =?UTF-8?q?e=20(prim=C3=A4r),=20controllerchange=20(Backup)=20=E2=80=94=20?= =?UTF-8?q?SW=20by-v797?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/main.py | 2 +- backend/static/index.html | 16 +++++++++++++--- backend/static/js/app.js | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/main.py b/backend/main.py index 0eb91e8..58b0679 100644 --- a/backend/main.py +++ b/backend/main.py @@ -327,7 +327,7 @@ MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media") os.makedirs(MEDIA_DIR, exist_ok=True) app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media") -APP_VER = "796" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "797" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/static/index.html b/backend/static/index.html index a6c708a..46ced7b 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -628,20 +628,30 @@ window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' }) .then(reg => { - // iOS PWA: Update sofort prüfen (Standalone-Modus prüft sonst nicht automatisch) reg.update(); + + // Primär: neuer SW hat aktiviert → sofort neu laden + reg.addEventListener('updatefound', () => { + const sw = reg.installing; + if (!sw) return; + sw.addEventListener('statechange', () => { + if (sw.state === 'activated') { + window.location.replace('/?_t=' + Date.now()); + } + }); + }); }) .catch(err => console.warn('SW Registration failed:', err)); }); - // iOS PWA: erneut prüfen wenn App aus dem Hintergrund kommt + // Backup: erneut prüfen wenn App aus dem Hintergrund kommt document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible') { navigator.serviceWorker.getRegistration().then(reg => reg?.update()); } }); - // Wenn neuer SW die Kontrolle übernimmt → Seite neu laden + // Backup: controllerchange (falls updatefound nicht feuert) navigator.serviceWorker.addEventListener('controllerchange', () => { window.location.replace('/?_t=' + Date.now()); }); diff --git a/backend/static/js/app.js b/backend/static/js/app.js index b1783e7..8ebb039 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '796'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '797'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.5.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; // Cache-Bust-Parameter nach Update-Reload sofort entfernen