diff --git a/app.rb b/app.rb index 18c665a..00b462f 100644 --- a/app.rb +++ b/app.rb @@ -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), diff --git a/public/css/style.css b/public/css/style.css index 6297dbc..dc24f39 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -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; diff --git a/public/js/map.js b/public/js/map.js index 1cdb43e..ca2f9ce 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -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) — diff --git a/public/js/update.js b/public/js/update.js index b5c01aa..85b3557 100644 --- a/public/js/update.js +++ b/public/js/update.js @@ -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 { diff --git a/views/index.erb b/views/index.erb index 867ef1a..c4c7642 100644 --- a/views/index.erb +++ b/views/index.erb @@ -107,6 +107,7 @@