Paint saved playlists before the launch sync and swap a background-downloaded update instantly
This commit is contained in:
@@ -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);
|
||||
})());
|
||||
}
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user