diff --git a/public/boot.js b/public/boot.js index e9983df..c390238 100644 --- a/public/boot.js +++ b/public/boot.js @@ -29,7 +29,15 @@ let lastBadge = Date.now(); badgePoll(); setInterval(() => { if (document.visibilityState === 'visible') { lastBadge = Date.now(); badgePoll(); } }, 2 * 60e3); document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible' && Date.now() - lastBadge > 30e3) { lastBadge = Date.now(); badgePoll(); } }); - if ('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js').catch(() => {}); + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js').catch(() => {}); + // tell the service worker who is signed in, so what it saves for offline use is kept for that person only + const who = () => navigator.serviceWorker.ready.then(r => (r.active || navigator.serviceWorker.controller || {}).postMessage && (r.active || navigator.serviceWorker.controller).postMessage({ type: 'who', id: ME ? ME.id : '' })).catch(() => {}); + who(); navigator.serviceWorker.addEventListener('controllerchange', who); + } + // offline: say so once, and that what is on screen is the last saved copy + { const note = () => { const el = document.getElementById('offnote') || Object.assign(document.createElement('div'), { id: 'offnote', role: 'status' }); el.textContent = 'You are offline. Showing what was last saved; changes need a connection.'; el.hidden = navigator.onLine; if (!el.isConnected) document.body.appendChild(el); }; + addEventListener('offline', note); addEventListener('online', note); if (!navigator.onLine) note(); } })(); // Keyboard (desktop): space play/pause, arrows seek, N/P next/previous. diff --git a/public/index.html b/public/index.html index 5323735..3a498b9 100644 --- a/public/index.html +++ b/public/index.html @@ -52,62 +52,62 @@