Feature: Stilles Auto-Update beim Seitenwechsel + Toast 'App auf v813 aktualisiert', Banner entfernt (SW by-v813)
This commit is contained in:
parent
047e5be986
commit
06022cf5da
5 changed files with 28 additions and 116 deletions
|
|
@ -3,7 +3,7 @@
|
|||
Router, State-Management, Navigation, Initialisierung.
|
||||
============================================================ */
|
||||
|
||||
const APP_VER = '812'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||
const APP_VER = '813'; // ← 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
|
||||
|
|
@ -119,6 +119,13 @@ const App = (() => {
|
|||
// ----------------------------------------------------------
|
||||
function navigate(pageId, pushHistory = true, params = {}) {
|
||||
if (!pages[pageId]) return;
|
||||
// Neue Version erkannt → jetzt sicher im Hintergrund aktualisieren
|
||||
if (window._byUpdatePending) {
|
||||
window._byUpdatePending = false;
|
||||
sessionStorage.setItem('by_updated_to', window._byNewVersion || '');
|
||||
location.href = '/force-update';
|
||||
return;
|
||||
}
|
||||
if (window.Worlds?._visible) window.Worlds.hide();
|
||||
|
||||
// Aktive Seite ausblenden
|
||||
|
|
@ -885,6 +892,13 @@ const App = (() => {
|
|||
|
||||
_bindNavigation();
|
||||
|
||||
// Nach stillem Update: Toast anzeigen
|
||||
const updatedTo = sessionStorage.getItem('by_updated_to');
|
||||
if (updatedTo) {
|
||||
sessionStorage.removeItem('by_updated_to');
|
||||
setTimeout(() => UI.toast?.success(`App automatisch auf v${updatedTo} aktualisiert`), 1500);
|
||||
}
|
||||
|
||||
try { localStorage.removeItem('by_wissen_open'); } catch (_) {}
|
||||
|
||||
_initVersionCheck();
|
||||
|
|
@ -986,108 +1000,8 @@ const App = (() => {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// VERSION-CHECK
|
||||
let _updateBannerShown = false;
|
||||
|
||||
async function _checkVersion() {
|
||||
try {
|
||||
const r = await fetch('/api/version', { cache: 'no-store' });
|
||||
if (!r.ok) return;
|
||||
const { version } = await r.json();
|
||||
if (version && version !== APP_VER && !_updateBannerShown) {
|
||||
_updateBannerShown = true;
|
||||
_showUpdateBanner(version);
|
||||
}
|
||||
} catch { /* offline — ignorieren */ }
|
||||
}
|
||||
|
||||
function _showUpdateBanner(newVersion) {
|
||||
const isIos = /iphone|ipad|ipod/i.test(navigator.userAgent);
|
||||
const existing = document.getElementById('app-update-banner');
|
||||
if (existing) return;
|
||||
|
||||
const banner = document.createElement('div');
|
||||
banner.id = 'app-update-banner';
|
||||
banner.style.cssText = [
|
||||
'position:fixed;bottom:calc(env(safe-area-inset-bottom,0px) + 72px);left:12px;right:12px',
|
||||
'z-index:9000;background:var(--c-primary);color:#fff;border-radius:16px',
|
||||
'padding:14px 16px;box-shadow:0 4px 20px rgba(0,0,0,0.3)',
|
||||
'display:flex;flex-direction:column;gap:10px',
|
||||
].join(';');
|
||||
|
||||
banner.innerHTML = `
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;gap:10px">
|
||||
<div>
|
||||
<div style="font-weight:700;font-size:var(--text-sm)">
|
||||
Neue Version verfügbar (v${newVersion})
|
||||
</div>
|
||||
<div style="font-size:var(--text-xs);opacity:0.85;margin-top:2px">
|
||||
Tippe auf Aktualisieren um die neueste Version zu laden.
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;gap:8px;flex-shrink:0">
|
||||
<button id="upd-btn-reload"
|
||||
style="background:rgba(255,255,255,0.2);border:1px solid rgba(255,255,255,0.4);
|
||||
color:#fff;border-radius:10px;padding:8px 14px;cursor:pointer;
|
||||
font-size:var(--text-sm);font-weight:700;white-space:nowrap">
|
||||
Aktualisieren
|
||||
</button>
|
||||
<button id="upd-btn-close"
|
||||
style="background:none;border:none;color:rgba(255,255,255,0.7);
|
||||
cursor:pointer;font-size:1.1rem;padding:4px 6px;line-height:1">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="upd-ios-hint" style="display:none;font-size:var(--text-xs);
|
||||
background:rgba(0,0,0,0.2);border-radius:10px;padding:10px 12px;line-height:1.6">
|
||||
${isIos
|
||||
? `Falls die App nach dem Aktualisieren noch die alte Version zeigt:<br>
|
||||
<strong>1.</strong> Drücke lange auf das App-Icon am Homescreen<br>
|
||||
<strong>2.</strong> Wähle „App entfernen" (nur das Symbol, keine Daten)<br>
|
||||
<strong>3.</strong> Öffne banyaro.app in Safari und füge die App erneut hinzu`
|
||||
: `Falls die Seite noch die alte Version zeigt:<br>
|
||||
Drücke <strong>Cmd+Shift+R</strong> (Mac) bzw. <strong>Ctrl+Shift+R</strong> (Windows/Android Chrome) für einen harten Reload.`}
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(banner);
|
||||
|
||||
banner.querySelector('#upd-btn-close').addEventListener('click', () => banner.remove());
|
||||
|
||||
banner.querySelector('#upd-btn-reload').addEventListener('click', () => {
|
||||
location.href = '/force-update';
|
||||
});
|
||||
}
|
||||
|
||||
function _initVersionCheck() {
|
||||
// Beim Start nach 10 Sekunden prüfen (nicht sofort — Prio für Auth)
|
||||
setTimeout(_checkVersion, 10_000);
|
||||
// Dann alle 30 Minuten
|
||||
setInterval(_checkVersion, 30 * 60_000);
|
||||
// Beim Wiedereinstieg in die App
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') _checkVersion();
|
||||
});
|
||||
// Nach Reload: war das ein Update-Reload? Falls Version immer noch alt → iOS-Hinweis
|
||||
const reloadVer = sessionStorage.getItem('by_update_reload');
|
||||
if (reloadVer && reloadVer === APP_VER) {
|
||||
// Version hat sich nicht geändert nach Reload → iOS-Cache-Problem
|
||||
sessionStorage.removeItem('by_update_reload');
|
||||
setTimeout(() => {
|
||||
fetch('/api/version', { cache: 'no-store' })
|
||||
.then(r => r.json())
|
||||
.then(({ version }) => {
|
||||
if (version && version !== APP_VER) {
|
||||
_updateBannerShown = true;
|
||||
_showUpdateBanner(version);
|
||||
// iOS-Hinweis sofort aufklappen
|
||||
setTimeout(() => {
|
||||
document.getElementById('upd-ios-hint')?.style.setProperty('display', 'block');
|
||||
}, 300);
|
||||
}
|
||||
}).catch(() => {});
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
// VERSION-CHECK — stilles Auto-Update beim nächsten Seitenwechsel
|
||||
function _initVersionCheck() { /* X-App-Version Header in api.js übernimmt das */ }
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// ÖFFENTLICHE API
|
||||
|
|
@ -1105,8 +1019,7 @@ const App = (() => {
|
|||
showOnboarding: _showOnboardingModal,
|
||||
updateNotifBadge: _updateNotifBadge,
|
||||
checkNearbyAlerts: _checkNearbyAlerts,
|
||||
loadScript: _loadScript,
|
||||
_triggerUpdateBanner: _showUpdateBanner };
|
||||
loadScript: _loadScript };
|
||||
|
||||
})();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue