Add update progress polling overlay and strengthen state flags

This commit is contained in:
Aaron
2025-12-10 20:08:28 -05:00
parent 9f17c1a087
commit 712efba6f9
3 changed files with 49 additions and 8 deletions

View File

@@ -106,6 +106,7 @@ const busyOverlay = document.getElementById("busyOverlay");
const busyTitle = document.getElementById("busyTitle");
const busyText = document.getElementById("busyText");
const toastContainer = document.getElementById("toastContainer");
const readyOverlay = document.getElementById("readyOverlay");
const TOAST_POS_KEY = "pikit-toast-pos";
const TOAST_ANIM_KEY = "pikit-toast-anim";
@@ -398,6 +399,7 @@ async function loadReleaseStatus() {
auto_check = false,
progress = null,
} = data || {};
window.__lastReleaseState = data;
setReleaseChip(data);
if (releaseCurrent) releaseCurrent.textContent = current_version;
if (releaseLatest) releaseLatest.textContent = latest_version;
@@ -485,9 +487,10 @@ function wireReleaseControls() {
releaseApplyBtn?.addEventListener("click", async () => {
try {
showBusy("Updating Pi-Kit…", "Applying release. This can take up to a minute.");
if (releaseProgress) releaseProgress.textContent = "Downloading and installing…";
await applyRelease();
await loadReleaseStatus();
pollReleaseStatus();
showToast("Update started", "success");
} catch (e) {
showToast(e.error || "Update failed", "error");
@@ -498,10 +501,11 @@ function wireReleaseControls() {
releaseRollbackBtn?.addEventListener("click", async () => {
try {
showBusy("Rolling back…", "Restoring previous backup.");
if (releaseProgress) releaseProgress.textContent = "Rolling back…";
await rollbackRelease();
await loadReleaseStatus();
showToast("Rollback complete", "success");
pollReleaseStatus();
showToast("Rollback started", "success");
} catch (e) {
showToast(e.error || "Rollback failed", "error");
} finally {
@@ -520,6 +524,27 @@ function wireReleaseControls() {
});
}
function pollReleaseStatus() {
let attempts = 0;
const maxAttempts = 30; // ~1 min at 2s
const tick = async () => {
attempts += 1;
await loadReleaseStatus();
const state = window.__lastReleaseState || {};
if (state.status === "in_progress" && attempts < maxAttempts) {
setTimeout(tick, 2000);
} else {
hideBusy();
if (state.status === "up_to_date") {
showToast("Update complete", "success");
} else if (state.status === "error") {
showToast(state.message || "Update failed", "error");
}
}
};
tick();
}
function showBusy(title = "Working…", text = "This may take a few seconds.") {
if (!busyOverlay) return;
busyTitle.textContent = title;