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