Web: neue Version lädt erst, wenn nichts spielt; kurze Gerätenamen, sw v61
All checks were successful
Build and push Docker image / build (push) Successful in 15s
Test / test (push) Successful in 5m57s

Bisher lud die Seite bei einer neuen Version sofort neu – auch mitten im
Radio oder Podcast. Jetzt erst, wenn nichts spielt, kein Buch offen ist
und kein Textfeld den Fokus hat. Der Browser heißt im Player-Sync kurz
„Chrome · Windows“.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mrwnslz 2026-10-02 15:37:38 +02:00
parent 262dd0d207
commit 779b54623e
3 changed files with 23 additions and 6 deletions

View file

@ -1352,10 +1352,26 @@ if ('serviceWorker' in navigator) {
}); });
}); });
// When a new SW activates it sends SW_ACTIVATED — reload to get fresh assets, // When a new SW activates it sends SW_ACTIVATED — reload to get fresh assets,
// but only if the reader isn't open (would interrupt reading). // but never in the middle of something: not while a book is open, radio or a
// podcast plays, or a text field has the focus — then as soon as that's over.
let reloadPending = false;
const busy = () => {
if (currentBookId || isPlaying) return true;
const host = window.DioraPodcastHost;
if (host && host.playerState) {
try { if (JSON.parse(host.playerState()).playing) return true; } catch (_) {}
}
const el = document.activeElement;
return !!el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName));
};
const reloadWhenIdle = () => {
if (busy()) setTimeout(reloadWhenIdle, 5000);
else window.location.reload();
};
navigator.serviceWorker.addEventListener('message', e => { navigator.serviceWorker.addEventListener('message', e => {
if (e.data?.type === 'SW_ACTIVATED' && !currentBookId) { if (e.data?.type === 'SW_ACTIVATED' && !reloadPending) {
window.location.reload(); reloadPending = true;
reloadWhenIdle();
} }
}); });
} }

View file

@ -937,11 +937,12 @@
: /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Web'; : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Web';
const os = /Android/.test(ua) ? 'Android' : /iPhone|iPad|iPod/.test(ua) ? 'iOS' : /Windows/.test(ua) ? 'Windows' const os = /Android/.test(ua) ? 'Android' : /iPhone|iPad|iPod/.test(ua) ? 'iOS' : /Windows/.test(ua) ? 'Windows'
: /Macintosh|Mac OS X/.test(ua) ? 'macOS' : /CrOS/.test(ua) ? 'ChromeOS' : /Linux/.test(ua) ? 'Linux' : ''; : /Macintosh|Mac OS X/.test(ua) ? 'macOS' : /CrOS/.test(ua) ? 'ChromeOS' : /Linux/.test(ua) ? 'Linux' : '';
return os ? browser + '/' + os : browser; return os ? browser + ' · ' + os : browser;
} }
const DEVICE_ID = deviceId(); const DEVICE_ID = deviceId();
const DEVICE_NAME = 'Browser (' + browserName() + ')'; // Short, it stands in the bar ("läuft auf Chrome · Windows").
const DEVICE_NAME = browserName();
const sync = { const sync = {
state: null, // the server's state, as last taken in state: null, // the server's state, as last taken in

View file

@ -2,7 +2,7 @@
* diora service worker — caches the app shell for offline use. * diora service worker — caches the app shell for offline use.
*/ */
const CACHE = 'diora-v60'; const CACHE = 'diora-v61';
const SHELL = [ const SHELL = [
'/static/css/app.css', '/static/css/app.css',
'/static/js/app.js', '/static/js/app.js',