From c657ac6ab8d14cb94dc524f2ebd1de2e1c8bc37d Mon Sep 17 00:00:00 2001 From: rene Date: Thu, 30 Apr 2026 16:48:37 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Update-Check=20vergleicht=20Server-Versi?= =?UTF-8?q?on=20mit=20lokaler=20=E2=80=94=20l=C3=A4dt=20Seite=20neu=20wenn?= =?UTF-8?q?=20Update=20gefunden,=20SW=20by-v561?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/static/js/app.js | 2 +- backend/static/js/pages/settings.js | 19 ++++++++++++++++--- backend/static/sw.js | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 45724cb..3a6efda 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 = '537'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '538'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.1.3'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; diff --git a/backend/static/js/pages/settings.js b/backend/static/js/pages/settings.js index 37f67b5..9a6b596 100644 --- a/backend/static/js/pages/settings.js +++ b/backend/static/js/pages/settings.js @@ -604,14 +604,27 @@ window.Page_settings = (() => { } if (btn) btn.textContent = 'Prüfe…'; try { + // Aktuelle Version vom Server holen (no-cache) + const serverResp = await fetch('/js/app.js', { cache: 'no-store' }); + const serverText = await serverResp.text(); + const match = serverText.match(/APP_VERSION\s*=\s*'([^']+)'/); + const serverVersion = match?.[1] || null; + const localVersion = typeof APP_VERSION !== 'undefined' ? APP_VERSION : '0'; + + // SW update anstoßen const reg = await navigator.serviceWorker.getRegistration(); await reg?.update(); - if (reg?.waiting) { - // Neuer SW wartet — sofort aktivieren + + if (serverVersion && serverVersion !== localVersion) { + // Neuere Version verfügbar — Seite neu laden + if (reg?.waiting) reg.waiting.postMessage({ type: 'SKIP_WAITING' }); + UI.toast.info(`Update auf v${serverVersion} verfügbar — Seite wird neu geladen…`); + setTimeout(() => location.reload(), 1500); + } else if (reg?.waiting) { reg.waiting.postMessage({ type: 'SKIP_WAITING' }); UI.toast.success('Update wird installiert…'); } else { - UI.toast.success('Ban Yaro ist aktuell — v' + (typeof APP_VERSION !== 'undefined' ? APP_VERSION : '1.0.0') + '.'); + UI.toast.success(`Ban Yaro ist aktuell — v${localVersion}`); } } catch { UI.toast.error('Update-Prüfung fehlgeschlagen.'); diff --git a/backend/static/sw.js b/backend/static/sw.js index aa968c2..7a41a97 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-v560'; +const CACHE_VERSION = 'by-v561'; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache