Fix: /force-update reload-Hänger + Cooldown persistent, SW by-v1106
User-Report: 'Leckerlis'-Screen verschwindet nicht mehr. Bug: Vorige Version nutzte 'await Promise.all([sw-unregister, caches.delete])' VOR dem Reload. Auf iOS-PWA können diese Promises gelegentlich nie resolven → Reload kommt nie. Fix /force-update: - Cleanup-Tasks fire-and-forget (kein await, kein Promise.all) - Sofort-Reload nach 150ms (kein await-Block) - Fallback 1: Nach 3s erscheint 'App neu starten'-Button für manuellen Tap - Fallback 2: Nach 6s automatisch location.href mit ?hard=1 Fix app.js Cooldown: - localStorage statt sessionStorage — überlebt PWA-App-Close - 10 Min statt 5 Min Cooldown (großzügiger Spielraum bei Update-Wellen)
This commit is contained in:
parent
b0ae71ba69
commit
c8ef4939f1
6 changed files with 52 additions and 42 deletions
|
|
@ -1763,32 +1763,40 @@ async def force_update():
|
|||
<title>Ban Yaro — Update</title>
|
||||
<style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;
|
||||
height:100vh;margin:0;background:#0f1623;color:#fff;flex-direction:column;gap:16px}
|
||||
p{color:#94a3b8;font-size:14px}</style></head>
|
||||
p{color:#94a3b8;font-size:14px}
|
||||
button{margin-top:24px;background:#C4843A;color:#fff;border:none;padding:12px 24px;
|
||||
border-radius:8px;font-size:16px;cursor:pointer}</style></head>
|
||||
<body>
|
||||
<div>⏳ Einen Moment…</div>
|
||||
<p id="s">Wir besorgen neue Leckerlis 🦴</p>
|
||||
<button id="b" style="display:none" onclick="location.replace('/?_t='+Date.now())">App neu starten</button>
|
||||
<script>
|
||||
// Zweiten Reload durch SW-updatefound verhindern
|
||||
sessionStorage.setItem('by_skip_sw_reload','1');
|
||||
// Warten bis SW-Unregister + Cache-Delete WIRKLICH durch sind (await),
|
||||
// dann mit Cache-Bust reloaden. Hard-Timeout 4s als Sicherheitsnetz.
|
||||
(async () => {
|
||||
const reload = () => location.replace('/?_t=' + Date.now());
|
||||
const safety = setTimeout(reload, 4000);
|
||||
try {
|
||||
const tasks = [];
|
||||
if (navigator.serviceWorker) {
|
||||
tasks.push(navigator.serviceWorker.getRegistrations()
|
||||
.then(r => Promise.all(r.map(s => s.unregister().catch(() => {})))));
|
||||
}
|
||||
tasks.push(caches.keys()
|
||||
.then(k => Promise.all(k.map(c => caches.delete(c).catch(() => {})))));
|
||||
await Promise.all(tasks);
|
||||
} catch (e) {}
|
||||
clearTimeout(safety);
|
||||
// Kurzes Delay damit der Browser die Storage-Operationen committet
|
||||
setTimeout(reload, 300);
|
||||
})();
|
||||
// Cleanup IM HINTERGRUND starten (fire-and-forget) — kein await,
|
||||
// kein Blockieren. Selbst wenn die Promises nie resolven (iOS-Bug),
|
||||
// hängen wir nicht.
|
||||
try {
|
||||
if (navigator.serviceWorker) {
|
||||
navigator.serviceWorker.getRegistrations()
|
||||
.then(r => r.forEach(s => s.unregister().catch(() => {})))
|
||||
.catch(() => {});
|
||||
}
|
||||
if (window.caches) {
|
||||
caches.keys()
|
||||
.then(k => k.forEach(c => caches.delete(c).catch(() => {})))
|
||||
.catch(() => {});
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
// Sofort reload — keine Promise-Abhängigkeit
|
||||
setTimeout(() => location.replace('/?_t=' + Date.now()), 150);
|
||||
|
||||
// Fallback: falls Reload nach 3s noch nicht passiert ist
|
||||
// (z.B. SW intercepted), Button anzeigen für manuellen Tap
|
||||
setTimeout(() => { document.getElementById('b').style.display = ''; }, 3000);
|
||||
|
||||
// Fallback 2: nach 6s automatisch nochmal versuchen mit hartem reload
|
||||
setTimeout(() => location.href = '/?_t=' + Date.now() + '&hard=1', 6000);
|
||||
</script></body></html>"""
|
||||
return HTMLResponse(content=html, headers={"Cache-Control": "no-store"})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue