Files
plainleaf/web/service_worker/util.ts
T
Zef HemelandGitHub dc2987a3f9 Sync engine rearchitecture (#1516)
* Don't require auth for .ping
* Finally introducing loggers
* Remove file list caching from disk_space_primitives
I don't think this is required anymore with the sync model
* Simplification of space primitives and more tests
* More reliable online status
* Add .zed settings
* Remove selfUpdate argument from `writeFile` no longer used
- Add `sync` config schema and document sync options
- Move sync config handling to client boot logic
- Move BootConfig type to ui_types.ts
- Remove sync env vars from server
- Update documentation for sync and architecture
* Improve sync logic and proxy routing for full sync state
* Add BoxProxy for late-bound client and improve Lua boot
- Add isMobile syscall for editor
* Add concurrency to sync process and log indexing duration
* Better service worker lifecycle management
2025-09-12 14:43:57 +02:00

43 lines
1.4 KiB
TypeScript

export async function unregisterServiceWorkers() {
if (navigator.serviceWorker) {
const registrations = await navigator.serviceWorker
.getRegistrations();
for (const registration of registrations) {
await registration.unregister();
console.log("Service worker unregistered");
}
} else {
console.error("No service worker found to unregister");
}
}
export function flushCachesAndUnregisterServiceWorker() {
console.log("Going to flush the caches and unregister the service worker");
return new Promise<void>((resolve) => {
if (!navigator.serviceWorker?.controller) {
console.log("No service worker active");
return resolve();
}
navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.type === "cacheFlushed") {
console.log("Cache flushed");
// Then unregister all service workers
navigator.serviceWorker.getRegistrations().then((registrations) => {
for (const registration of registrations) {
registration.unregister();
console.log("Service worker unregistered");
resolve();
}
});
}
});
// First flush active cache
navigator.serviceWorker.ready.then((registration) => {
console.log("Sending request to flush cache");
registration.active!.postMessage({ type: "flush-cache" });
});
});
}