Status / debug: "Check for an update now" — past the update check's 10 min cache
This commit is contained in:
1 parent
d58f7efc41
commit
a11a71dc89
5 files changed
+17
-6
No files matched your search
+12
-5
@@ -5,23 +5,30 @@
|
||||
const CHECK_MS = 10 * 60 * 1000;
|
||||
const RESTART_POLL_MS = 5000;
|
||||
|
||||
export function setupUpdate(button) {
|
||||
export function setupUpdate(button, checkNow) {
|
||||
let latest = null;
|
||||
let timer = null;
|
||||
|
||||
async function check() {
|
||||
async function check(fresh = false) {
|
||||
clearTimeout(timer);
|
||||
try {
|
||||
const state = await (await fetch("/api/update", { cache: "no-store" })).json();
|
||||
const state = await (await fetch(`/api/update${fresh ? "?fresh=1" : ""}`, { cache: "no-store" })).json();
|
||||
if (!state.enabled) return;
|
||||
if (checkNow) {
|
||||
checkNow.hidden = false;
|
||||
if (fresh) checkNow.textContent = state.available ? `Update ${state.latest} available ↑` : `Up to date (${state.current}) — check again`;
|
||||
}
|
||||
latest = state.latest;
|
||||
button.hidden = !state.available;
|
||||
button.textContent = `⟳ ${state.latest}`;
|
||||
button.title = `A new version (${state.latest}, now ${state.current}) — click to update; the app restarts for about a minute`;
|
||||
if (state.status?.state === "failed") button.title += `\nThe last update failed: ${state.status.message}`;
|
||||
setTimeout(check, CHECK_MS);
|
||||
timer = setTimeout(check, CHECK_MS);
|
||||
} catch {
|
||||
setTimeout(check, CHECK_MS);
|
||||
timer = setTimeout(check, CHECK_MS);
|
||||
}
|
||||
}
|
||||
checkNow?.addEventListener("click", () => check(true));
|
||||
|
||||
async function waitForRestart(revision) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user