Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Check for updates from the version in the sidebar

emanuele-em3c58b9ce00db
diff --git a/src/app.js b/src/app.js
index adc66cc..348a47f 100644
--- a/src/app.js
+++ b/src/app.js
@@ -283,6 +283,7 @@ function setProject(slug) {
}
function render() {
+ if (!$("#version").disabled) $("#version").textContent = `v${state.board.version}`;
renderNav();
renderHeader();
renderColumns();
@@ -1067,23 +1068,51 @@ schedulePoll();
// ---------- update ----------
-// When a newer release is out, the sidebar offers it. The server checks at most every
-// few hours, installs it over itself and restarts; the page reloads once it is back.
+// Kanzo checks GitHub for a newer release once a day and offers it at the bottom of the
+// sidebar; clicking the version there asks right away. Installing replaces the running board
+// and restarts it, and the page reloads once it's back.
async function checkUpdate() {
try {
- const { current, available } = await api("GET", "/update");
- const button = $("#update");
- button.hidden = !available;
- if (!available) return;
- $("#update-label").textContent = `Update to ${available}`;
- button.title = `You have ${current}`;
- button.onclick = () => installUpdate(current, available);
+ showUpdate(await api("GET", "/update"));
} catch {}
}
-async function installUpdate(current, available) {
- if (!confirm(`Update Kanzo from ${current} to ${available}? The board restarts, which takes a few seconds.`)) return;
+function showUpdate({ current, available }) {
+ const button = $("#update");
+ button.hidden = !available;
+ if (!available) return;
+ $("#update-label").textContent = `Update to ${available}`;
+ button.title = `You have ${current}`;
+ button.onclick = () => {
+ if (confirm(`Update Kanzo from ${current} to ${available}? The board restarts, which takes a few seconds.`)) installUpdate(available);
+ };
+}
+
+// The version at the bottom of the sidebar checks for updates when clicked.
+$("#version").addEventListener("click", async () => {
+ const button = $("#version");
+ button.disabled = true;
+ button.textContent = "Checking…";
+ try {
+ const status = await api("GET", "/update?now=1");
+ showUpdate(status);
+ if (status.available) {
+ if (confirm(`Kanzo ${status.available} is out (you have ${status.current}). Download and install it now? The board restarts.`)) {
+ installUpdate(status.available);
+ }
+ } else if (status.latest) {
+ toast(`Kanzo is up to date (${status.current})`);
+ } else {
+ toast("Can't reach GitHub to check for updates");
+ }
+ } catch (err) { toast(err.message); }
+ button.disabled = false;
+ button.textContent = state.board ? `v${state.board.version}` : "";
+});
+
+async function installUpdate(available) {
const button = $("#update");
+ button.hidden = false;
button.disabled = true;
$("#update-label").textContent = "Updating…";
try {
@@ -1103,7 +1132,7 @@ async function installUpdate(current, available) {
}
checkUpdate();
-setInterval(checkUpdate, 6 * 60 * 60 * 1000);
+setInterval(checkUpdate, 24 * 60 * 60 * 1000);
// Relative times ("5m ago") drift; refresh them now and then.
setInterval(() => {
diff --git a/src/index.html b/src/index.html
index 3db8f31..fbe91a6 100644
--- a/src/index.html
+++ b/src/index.html
@@ -102,6 +102,10 @@ aside {
.update { margin-top: 8px; background: var(--hover); }
.update:hover, .update:focus-visible { background: var(--active); }
.update:disabled { opacity: .6; cursor: default; }
+.about { display: flex; align-items: center; gap: 8px; padding: 10px 10px 0; color: var(--faint); font-size: 12px; }
+.about .ghost { width: auto; margin-left: -6px; padding: 2px 6px; font-size: 12px; color: var(--faint); }
+.about .ghost:hover, .about .ghost:focus-visible { color: var(--text); }
+.about .ghost:disabled { cursor: default; }
form.new-project { display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 10px; }
form.new-project .row { display: flex; gap: 6px; margin-top: 2px; }
@@ -329,7 +333,7 @@ header .sub a:hover { color: var(--text); }
.nav { flex-direction: row; overflow-x: auto; }
.nav a { width: auto; }
.nav .label { display: none; }
- #new-project-toggle, form.new-project { display: none; }
+ #new-project-toggle, form.new-project, .about { display: none; }
.columns { grid-auto-columns: minmax(78vw, 1fr); padding: 0 12px 12px; }
header { padding: 12px; }
}
@@ -354,6 +358,9 @@ header .sub a:hover { color: var(--text); }
</form>
<nav class="nav" id="nav"></nav>
<button class="ghost update" id="update" hidden><span class="icon" data-icon="update"></span><span id="update-label"></span></button>
+ <div class="about">
+ <button class="ghost" id="version" title="Check for updates"></button>
+ </div>
</aside>
<main>
diff --git a/src/update.rs b/src/update.rs
index 84a3d7c..0e0393e 100644
--- a/src/update.rs
+++ b/src/update.rs
@@ -14,8 +14,8 @@ pub const CURRENT: &str = env!("CARGO_PKG_VERSION");
/// Where releases are published; `KANZO_RELEASES_URL` points elsewhere, for tests.
const RELEASES: &str = "https://github.com/emanuele-em/kanzo/releases/latest/download";
-/// How long a check for the latest version is reused.
-const CHECK_EVERY: Duration = Duration::from_secs(6 * 60 * 60);
+/// How long a check for the latest version is reused: the board checks once a day.
+const CHECK_EVERY: Duration = Duration::from_secs(24 * 60 * 60);
static LATEST: Mutex<Option<(Instant, Option<String>)>> = Mutex::new(None);
@@ -28,11 +28,12 @@ fn curl(url: &str) -> Option<Vec<u8>> {
out.status.success().then_some(out.stdout)
}
-/// The latest released version, checked at most every few hours; `None` when it
-/// can't be found, like offline.
-pub fn latest() -> Option<String> {
+/// The latest released version, checked at most once a day unless `now`; `None` when
+/// it can't be found, like offline.
+pub fn latest(now: bool) -> Option<String> {
let mut cached = LATEST.lock().unwrap_or_else(|e| e.into_inner());
if let Some((at, version)) = &*cached
+ && !now
&& at.elapsed() < CHECK_EVERY
{
return version.clone();
diff --git a/src/web.rs b/src/web.rs
index b2d1dac..f440d9d 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -291,6 +291,7 @@ async fn board(State(home): Shared, Query(q): Query<BoardQuery>) -> Response {
"projects": s.list_projects()?,
"tasks": tasks,
"done_hidden": done_hidden,
+ "version": update::CURRENT,
"changes": change_token(h, s)?,
}))
})
@@ -539,11 +540,19 @@ async fn save_image(State(home): Shared, headers: HeaderMap, body: Bytes) -> Res
}
}
-/// This version, and a newer released one if there is.
-async fn update_status() -> Response {
- let latest = tokio::task::spawn_blocking(update::latest).await.ok().flatten();
- let available = latest.filter(|v| update::newer(v));
- Json(json!({ "current": update::CURRENT, "available": available })).into_response()
+#[derive(Deserialize)]
+struct UpdateQuery {
+ /// Present to check GitHub now rather than reuse today's answer.
+ now: Option<String>,
+}
+
+/// This version, the latest release (`null` when GitHub can't be reached) and, when
+/// that one is newer, `available`.
+async fn update_status(Query(q): Query<UpdateQuery>) -> Response {
+ let now = q.now.is_some();
+ let latest = tokio::task::spawn_blocking(move || update::latest(now)).await.ok().flatten();
+ let available = latest.clone().filter(|v| update::newer(v));
+ Json(json!({ "current": update::CURRENT, "latest": latest, "available": available })).into_response()
}
/// Installs the latest release over this program, answers, then starts it in place.