Skip to content

Commit

Permalink
prioritize service worker update
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Oct 2, 2024
1 parent 468c770 commit b560fb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions pkg/app/gen/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ goappInitWebAssembly();
// -----------------------------------------------------------------------------
async function goappInitServiceWorker() {
if ("serviceWorker" in navigator) {
window.addEventListener("load", async () => {
try {
const registration = await navigator.serviceWorker.register(
"{{.WorkerJS}}"
);
goappServiceWorkerRegistration = registration;
goappSetupNotifyUpdate(registration);
goappSetupPushNotification();
} catch (err) {
console.error("goapp service worker registration failed: ", err);
}
});
try {
const registration = await navigator.serviceWorker.register(
"{{.WorkerJS}}"
);
goappServiceWorkerRegistration = registration;
goappSetupNotifyUpdate(registration);
goappSetupPushNotification();
} catch (err) {
console.error("goapp service worker registration failed: ", err);
}
}
}

Expand All @@ -61,8 +59,12 @@ function goappSetupNotifyUpdate(registration) {
registration.addEventListener("updatefound", (event) => {
const newSW = registration.installing;
newSW.addEventListener("statechange", (event) => {
if (!navigator.serviceWorker.controller) {
return;
}

switch (newSW.state) {
case "activated":
case "installed":
goappOnUpdate();
}
});
Expand Down
Loading

0 comments on commit b560fb3

Please sign in to comment.