From 4353994c685fd43f551ba835430290f52f2be291 Mon Sep 17 00:00:00 2001 From: rene Date: Sun, 26 Apr 2026 08:38:50 +0200 Subject: [PATCH] =?UTF-8?q?iOS=20PWA:=20reg.update()=20beim=20Start=20+=20?= =?UTF-8?q?visibilitychange=20=E2=80=94=20SW=20by-v412?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iOS prüft im Standalone-Modus nicht automatisch ob ein neuer SW vorliegt. reg.update() erzwingt die Prüfung beim App-Öffnen und beim Zurückkehren aus dem Hintergrund — der bestehende controllerchange→reload greift dann. --- backend/static/index.html | 18 +++++++++++++++--- backend/static/sw.js | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/static/index.html b/backend/static/index.html index 8222594..9c55546 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -458,13 +458,25 @@ if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' }) - .catch(err => console.log('SW Registration failed:', err)); + .then(reg => { + // iOS PWA: Update sofort prüfen (Standalone-Modus prüft sonst nicht automatisch) + reg.update(); + }) + .catch(err => console.warn('SW Registration failed:', err)); }); - // Wenn ein neuer SW die Kontrolle übernimmt (nach Update), - // Seite neu laden — sonst hat app.js neue Seiten-JS aber altes api.js im Speicher. + + // iOS PWA: 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 navigator.serviceWorker.addEventListener('controllerchange', () => { window.location.reload(); }); + navigator.serviceWorker.addEventListener('message', e => { if (e.data?.type === 'CHECK_NEARBY_ALERTS') { window.App?._checkNearbyAlerts?.(); diff --git a/backend/static/sw.js b/backend/static/sw.js index 0ea787f..9d7983e 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -3,7 +3,7 @@ Offline-Cache + Push Notifications + Tile-Cache ============================================================ */ -const CACHE_VERSION = 'by-v411'; +const CACHE_VERSION = 'by-v412'; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten