diff --git a/static/js/app.js b/static/js/app.js index 15b2139..5ca46fc 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1352,10 +1352,26 @@ if ('serviceWorker' in navigator) { }); }); // 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 => { - if (e.data?.type === 'SW_ACTIVATED' && !currentBookId) { - window.location.reload(); + if (e.data?.type === 'SW_ACTIVATED' && !reloadPending) { + reloadPending = true; + reloadWhenIdle(); } }); } diff --git a/static/js/podcasts-web.js b/static/js/podcasts-web.js index 559192c..e9091b1 100644 --- a/static/js/podcasts-web.js +++ b/static/js/podcasts-web.js @@ -937,11 +937,12 @@ : /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' : /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_NAME = 'Browser (' + browserName() + ')'; + // Short, it stands in the bar ("läuft auf Chrome · Windows"). + const DEVICE_NAME = browserName(); const sync = { state: null, // the server's state, as last taken in diff --git a/static/js/sw.js b/static/js/sw.js index 4fb34d3..7c776ea 100644 --- a/static/js/sw.js +++ b/static/js/sw.js @@ -2,7 +2,7 @@ * diora service worker — caches the app shell for offline use. */ -const CACHE = 'diora-v60'; +const CACHE = 'diora-v61'; const SHELL = [ '/static/css/app.css', '/static/js/app.js',