Skip to content

Commit

Permalink
bump version and update cache when detecting new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SalatielSauer committed Nov 13, 2023
1 parent 2e46c3e commit cecf82f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 18 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,24 @@ <h2 id="filesystem-status"></h2>
<script>
if ("serviceWorker" in navigator) {
const basePath = location.href.replace(/\/[^\/]+$/, "");
navigator.serviceWorker.register(`${basePath}pwapp.js`, { scope: basePath });
navigator.serviceWorker.register(`${basePath}pwapp.js`, { scope: basePath })
.then(reg => {
reg.addEventListener("updatefound", () => {
const newWorker = reg.installing;
newWorker.addEventListener("statechange", () => {
if (newWorker.state === "installed" && navigator.serviceWorker.controller) {
console.log("New OGZ-Editor version is available; please refresh.");
FS_fileStatus.update(1, `Checking new version...`, "fas fa-spinner fa-spin");
}
});
});
});
navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.type === 1) {
FS_fileStatus.update(1, `Updating OGZ Editor to ${event.data.body}...`, "fas fa-spinner fa-spin");
window.location.reload();
}
});
};
</script>
</body>
Expand Down
9 changes: 8 additions & 1 deletion pwapp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const version = "0.1.4.1";
const version = "0.1.5";
const cacheName = `ogzeditor-${version}`;
console.log("running", cacheName);
self.addEventListener("install", (e) => {
Expand All @@ -25,6 +25,13 @@ self.addEventListener("activate", (event) => {
return caches.delete(key); // remove old caches
}
}));
}).then(() => {
self.clients.matchAll().then(clients => {
clients.forEach(client => {
client.postMessage({type: 1, body: version});
});
});
return self.clients.claim();
})
);
});
Expand Down

0 comments on commit cecf82f

Please sign in to comment.