Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: improve update installation

Abdullah Attabf0d6857d316
diff --git a/apps/web/src/utils/updater.ts b/apps/web/src/utils/updater.ts
index 909060145..b0052defa 100644
--- a/apps/web/src/utils/updater.ts
+++ b/apps/web/src/utils/updater.ts
@@ -73,13 +73,19 @@ export async function installUpdate() {
else {
const registrations =
(await navigator.serviceWorker?.getRegistrations()) || [];
- let reload = false;
for (const registration of registrations) {
if (registration.waiting) {
+ registration.waiting.addEventListener("statechange", () => {
+ const worker =
+ registration.active ||
+ registration.waiting ||
+ registration.installing;
+ if (worker?.state === "activated") {
+ window.location.reload();
+ }
+ });
registration.waiting.postMessage({ type: "SKIP_WAITING" });
- reload = true;
}
}
- if (reload) window.location.reload();
}
}