Spaces:
Running
Running
Reload into new versions when idle
Browse files- src/update.js +13 -0
src/update.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Pick up new versions on the next launch instead of the one after: when a new
|
| 2 |
+
// service worker takes over, reload — unless a conversion or playback is running,
|
| 3 |
+
// in which case wait until it's idle.
|
| 4 |
+
if ('serviceWorker' in navigator) {
|
| 5 |
+
const hadController = !!navigator.serviceWorker.controller;
|
| 6 |
+
const busy = () => !document.getElementById('ex-bar')?.classList.contains('hidden')
|
| 7 |
+
|| !document.getElementById('audio')?.paused;
|
| 8 |
+
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
| 9 |
+
if (!hadController) return; // first install: nothing stale to replace
|
| 10 |
+
const tryReload = () => (busy() ? setTimeout(tryReload, 3000) : location.reload());
|
| 11 |
+
tryReload();
|
| 12 |
+
});
|
| 13 |
+
}
|