Add update progress polling overlay and strengthen state flags
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -1374,6 +1374,11 @@ select:focus-visible,
|
||||
#addServiceModal .controls {
|
||||
padding: 0 2px 4px;
|
||||
}
|
||||
|
||||
/* Busy overlay already defined; ensure modal width for release modal */
|
||||
#releaseModal .modal-card.wide {
|
||||
max-width: 760px;
|
||||
}
|
||||
.modal:not(.hidden) .modal-card {
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user