// Pick up new versions on the next launch instead of the one after: when a new // service worker takes over, reload — unless a conversion or playback is running, // in which case wait until it's idle. if ('serviceWorker' in navigator) { const hadController = !!navigator.serviceWorker.controller; const busy = () => !document.getElementById('ex-bar')?.classList.contains('hidden') || !document.getElementById('audio')?.paused; navigator.serviceWorker.addEventListener('controllerchange', () => { if (!hadController) return; // first install: nothing stale to replace const tryReload = () => (busy() ? setTimeout(tryReload, 3000) : location.reload()); tryReload(); }); }