Paint saved playlists before the launch sync and swap a background-downloaded update instantly

This commit is contained in:
Jonathan Sykes
2026-09-22 13:27:12 +08:00
parent 691e204d61
commit 987697e759
7 changed files with 300 additions and 18 deletions

View File

@@ -176,6 +176,24 @@ self.addEventListener('message', (e) => {
if (e.data && e.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
// "Is your shell already downloaded?" — a waiting worker has precached the
// whole new build during install, so "Refresh UI" can swap to it instantly
// instead of downloading everything a second time. Answer honestly: install
// deletes its cache on failure, but a cache can also be evicted under
// storage pressure, so the files are actually checked.
if (e.data && e.data.type === 'CACHE_STATUS') {
e.waitUntil((async () => {
let missing = SHELL.length;
try {
const cache = await caches.open(CACHE);
const found = await Promise.all(SHELL.map((url) => cache.match(url)));
missing = found.filter((r) => !r).length;
} catch { /* storage blocked — report not ready */ }
const reply = { type: 'CACHE_STATUS', version: VERSION, ready: missing === 0, missing };
if (e.ports && e.ports[0]) e.ports[0].postMessage(reply);
else if (e.source) e.source.postMessage(reply);
})());
}
});
// ============================================================================