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
|
|
@ -341,7 +341,7 @@ MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media")
|
||||||
os.makedirs(MEDIA_DIR, exist_ok=True)
|
os.makedirs(MEDIA_DIR, exist_ok=True)
|
||||||
app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media")
|
app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media")
|
||||||
|
|
||||||
APP_VER = "812" # muss mit APP_VER in app.js übereinstimmen
|
APP_VER = "813" # muss mit APP_VER in app.js übereinstimmen
|
||||||
|
|
||||||
@app.get("/.well-known/assetlinks.json")
|
@app.get("/.well-known/assetlinks.json")
|
||||||
async def assetlinks():
|
async def assetlinks():
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,9 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
|
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
|
||||||
<link rel="stylesheet" href="/css/design-system.css?v=812">
|
<link rel="stylesheet" href="/css/design-system.css?v=813">
|
||||||
<link rel="stylesheet" href="/css/layout.css?v=812">
|
<link rel="stylesheet" href="/css/layout.css?v=813">
|
||||||
<link rel="stylesheet" href="/css/components.css?v=812">
|
<link rel="stylesheet" href="/css/components.css?v=813">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
@ -581,10 +581,10 @@
|
||||||
<div id="modal-container"></div>
|
<div id="modal-container"></div>
|
||||||
|
|
||||||
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
|
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
|
||||||
<script src="/js/api.js?v=812"></script>
|
<script src="/js/api.js?v=813"></script>
|
||||||
<script src="/js/ui.js?v=812"></script>
|
<script src="/js/ui.js?v=813"></script>
|
||||||
<script src="/js/app.js?v=812"></script>
|
<script src="/js/app.js?v=813"></script>
|
||||||
<script src="/js/worlds.js?v=812"></script>
|
<script src="/js/worlds.js?v=813"></script>
|
||||||
|
|
||||||
<!-- Feature-Seiten werden lazy geladen -->
|
<!-- Feature-Seiten werden lazy geladen -->
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,7 @@ const API = (() => {
|
||||||
const serverVer = response.headers.get('x-app-version');
|
const serverVer = response.headers.get('x-app-version');
|
||||||
if (serverVer && serverVer !== APP_VER && !window._byUpdatePending) {
|
if (serverVer && serverVer !== APP_VER && !window._byUpdatePending) {
|
||||||
window._byUpdatePending = true;
|
window._byUpdatePending = true;
|
||||||
// App._showUpdateBanner wird aufgerufen sobald App initialisiert ist
|
window._byNewVersion = serverVer;
|
||||||
setTimeout(() => window.App?._triggerUpdateBanner?.(serverVer), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status === 204) return null;
|
if (response.status === 204) return null;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Router, State-Management, Navigation, Initialisierung.
|
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 APP_VERSION = '1.5.0'; // ← semantische Version, wird bei make release gesetzt
|
||||||
const IS_STAGING = location.hostname === 'staging.banyaro.app';
|
const IS_STAGING = location.hostname === 'staging.banyaro.app';
|
||||||
// Cache-Bust-Parameter nach Update-Reload sofort entfernen
|
// Cache-Bust-Parameter nach Update-Reload sofort entfernen
|
||||||
|
|
@ -119,6 +119,13 @@ const App = (() => {
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
function navigate(pageId, pushHistory = true, params = {}) {
|
function navigate(pageId, pushHistory = true, params = {}) {
|
||||||
if (!pages[pageId]) return;
|
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();
|
if (window.Worlds?._visible) window.Worlds.hide();
|
||||||
|
|
||||||
// Aktive Seite ausblenden
|
// Aktive Seite ausblenden
|
||||||
|
|
@ -885,6 +892,13 @@ const App = (() => {
|
||||||
|
|
||||||
_bindNavigation();
|
_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 (_) {}
|
try { localStorage.removeItem('by_wissen_open'); } catch (_) {}
|
||||||
|
|
||||||
_initVersionCheck();
|
_initVersionCheck();
|
||||||
|
|
@ -986,108 +1000,8 @@ const App = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// VERSION-CHECK
|
// VERSION-CHECK — stilles Auto-Update beim nächsten Seitenwechsel
|
||||||
let _updateBannerShown = false;
|
function _initVersionCheck() { /* X-App-Version Header in api.js übernimmt das */ }
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------
|
// ----------------------------------------------------------
|
||||||
// ÖFFENTLICHE API
|
// ÖFFENTLICHE API
|
||||||
|
|
@ -1105,8 +1019,7 @@ const App = (() => {
|
||||||
showOnboarding: _showOnboardingModal,
|
showOnboarding: _showOnboardingModal,
|
||||||
updateNotifBadge: _updateNotifBadge,
|
updateNotifBadge: _updateNotifBadge,
|
||||||
checkNearbyAlerts: _checkNearbyAlerts,
|
checkNearbyAlerts: _checkNearbyAlerts,
|
||||||
loadScript: _loadScript,
|
loadScript: _loadScript };
|
||||||
_triggerUpdateBanner: _showUpdateBanner };
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Offline-Cache + Push Notifications + Tile-Cache
|
Offline-Cache + Push Notifications + Tile-Cache
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
const CACHE_VERSION = 'by-v812';
|
const CACHE_VERSION = 'by-v813';
|
||||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||||
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache
|
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue