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
@@ -511,6 +511,7 @@ module Maptool
|
||||
require_login!
|
||||
halt json(enabled: false) unless SELF_UPDATE
|
||||
|
||||
Updater.reset! if params[:fresh] # "Check now": past the 10 min cache
|
||||
latest = Updater.latest(GITEA_URL, UPDATE_REPO)
|
||||
available = !!latest && latest[:ci] == "success" && latest[:sha] && !latest[:sha].start_with?(REVISION)
|
||||
json enabled: true, current: REVISION, latest: latest&.dig(:sha)&.slice(0, 7), ci: latest&.dig(:ci),
|
||||
|
||||
@@ -721,6 +721,8 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
||||
font-size: 14px;
|
||||
color: var(--accent);
|
||||
}
|
||||
button.basemap-panel__link { width: 100%; border: none; background: none; text-align: left; font-family: inherit; cursor: pointer; }
|
||||
button.basemap-panel__link[hidden] { display: none; }
|
||||
|
||||
.basemap-panel__sources[hidden] {
|
||||
display: none;
|
||||
|
||||
+1
-1
@@ -557,7 +557,7 @@ gnssControl.mount(sidebar);
|
||||
new LiveTrackPanelControl(map).mount(sidebar);
|
||||
|
||||
if (isLoggedIn()) new DebugControl().mount(sidebar);
|
||||
if (isLoggedIn()) setupUpdate(document.querySelector(".topbar__update"));
|
||||
if (isLoggedIn()) setupUpdate(document.querySelector(".topbar__update"), document.querySelector(".debug-panel__update-check"));
|
||||
setupSidePanelModes();
|
||||
|
||||
// The sidebar already has a "Base map" icon (opens the same panel) —
|
||||
|
||||
+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 {
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
</div>
|
||||
<div class="basemap-panel__list">
|
||||
<a class="basemap-panel__link" href="/can.html" target="_blank">CANopen diagnostics ↗</a>
|
||||
<button type="button" class="basemap-panel__link debug-panel__update-check" hidden>Check for an update now</button>
|
||||
</div>
|
||||
<!-- Filled by DebugControl (public/js/debug.js), logged-in only. -->
|
||||
<div class="debug-panel__body"></div>
|
||||
|
||||
Reference in new issue
Block a user