Fix: Update-Check vergleicht Server-Version mit lokaler — lädt Seite neu wenn Update gefunden, SW by-v561
This commit is contained in:
parent
7cf60a848f
commit
c657ac6ab8
3 changed files with 18 additions and 5 deletions
|
|
@ -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';
|
||||
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue