Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

about: the Version row and the title bar hold still while the update's state comes in (#4057)

yetone89f3865efa20
diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css
index 600ff792f..e6f804185 100644
--- a/internal/gui/assets/app.css
+++ b/internal/gui/assets/app.css
@@ -270,9 +270,12 @@ body.panel .seg { display: none; }
WebKit turns a whole svg on a layer snapped to the pixel grid, so off a
whole pixel its ring circles about a point a pixel or so off its centre */
.icon.spin svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .9s linear infinite; }
-/* a newer magpie is ready: a quiet pill before the header's icons */
+/* a newer magpie is ready: a quiet pill before the header's icons. It
+ opens from nothing, so the title bar's tools beside the sidebar (app.js
+ tools) slide over to make room, not jump 80px at once (#4057) */
.update {
align-self: center; display: inline-flex; align-items: center; gap: 4px;
+ max-width: 20em; overflow: hidden;
height: 22px; margin-right: 6px; padding: 0 9px 0 7px; border-radius: 999px;
font-size: 11.5px; font-weight: 560; letter-spacing: .005em; white-space: nowrap;
color: var(--accent); background: var(--accent-soft);
@@ -336,7 +339,7 @@ body.window .top.inrow .actions { margin-left: 0; }
body.web .top #nav button { flex: none; height: 40px; padding: 0 14px; font-size: 14px; }
body.web .top .actions { gap: 4px; }
}
-@keyframes update-in { from { opacity: 0; transform: translateY(-3px) scale(.94); } }
+@keyframes update-in { from { opacity: 0; max-width: 0; margin-right: 0; padding: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
/* ---- the sidebar (app.js layoutNav) -------------------------------------- */
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index a9ae5e934..596ecae2d 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -4272,7 +4272,7 @@ function updatePath(p) {
async function renderUpdateBadge() {
const b = $("#update"), label = b.querySelector("span");
const u = await api(updatePath("update")).catch(() => null);
- if (u) updateLast = u;
+ if (u) updateLast = u, u.at = Date.now();
// pulling: a click is downloading it again, and restarts once it's in
const pulling = !!u && !!b.dataset.pulling && ["checking", "downloading", "ready"].includes(u.state);
if (b.dataset.pulling && !pulling) {
@@ -22486,25 +22486,23 @@ function editRedactRule(r, n, row) {
}
// renderUpdate fills in the version row: whether a newer magpie is out.
-// The app checks and downloads on its own, so usually the row just offers
-// the restart; a check can also be asked for. That check leaves the button
-// where it is, dimmed, and a second click does nothing. A read still out
-// from before the answer is not drawn over it. A row drawn again draws the
-// last state at once, but in a check (#3469), and reads while a check or a
-// download is under way.
+// A check asked for dims its button, ignores a second click, and isn't
+// drawn over by an older read. A row drawn again draws a state read in the
+// last 30s at once (#3469); an older one may be stale, so it waits (#4057).
let updateBusy = false, updateLast = null;
const updateSeq = new WeakMap(), seqOf = (r) => updateSeq.get(r) || 0;
async function renderUpdate(r, u) {
const seq = seqOf(r);
if (u == null) {
- const early = !updateBusy && updateLast && !r.querySelector(".sub");
+ const bare = !r.querySelector(".sub"), early = bare && !updateBusy && Date.now() - updateLast?.at < 3e4;
if (early) renderUpdate(r, updateLast);
+ else if (bare) r.querySelector(".who").append(el("div", "sub", "\u00a0"));
u = await api(updatePath("update?fresh=1")).catch(() => null);
if (!u || !r.isConnected || seqOf(r) !== seq) return;
if (early) updateSeq.set(r, seq + 1); // stops timers
} else if (!r.isConnected) return;
- updateLast = u;
+ updateLast = u, u.at ??= Date.now();
const who = r.querySelector(".who"), val = r.querySelector(".val");
const sub = who.querySelector(".sub") || who.appendChild(el("div", "sub"));
sub.title = "";
diff --git a/internal/gui/tests/update-row-steady.test.cjs b/internal/gui/tests/update-row-steady.test.cjs
new file mode 100644
index 000000000..f120e5a25
--- /dev/null
+++ b/internal/gui/tests/update-row-steady.test.cjs
@@ -0,0 +1,174 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// Settings › About and the title bar hold still while the update's state
+// comes in (#4057):
+// - opened cold, with no state read yet, the Version row keeps the line
+// under its name for the answer, rather than growing 12px when it lands;
+// - opened with a state read a minute ago ("Up to date") while a check has
+// since downloaded a newer version, that old state isn't drawn first and
+// swapped for "0.1.401 is downloaded";
+// - the header's Update pill showing opens from nothing, so the Settings
+// search in the title bar beside the sidebar slides over with it rather
+// than jumping 80px left in one frame.
+// English and Chinese; no backend, the API is faked here.
+const assert = require("node:assert/strict");
+const fs = require("node:fs/promises");
+const path = require("node:path");
+const { test } = require("node:test");
+const { chromium, webkit } = require("playwright");
+const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
+
+const assets = path.resolve(__dirname, "../assets");
+const words = {
+ en: { version: "Version", latest: "Up to date", ready: "0.1.401 is downloaded" },
+ zh: { version: "版本", latest: "已是最新", ready: "0.1.401 已下载" },
+};
+
+function server(lang, ctl) {
+ const settings = {
+ theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", proxy: "", redact: false, redactWords: [],
+ version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none",
+ visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
+ };
+ return async (route) => {
+ const url = new URL(route.request().url());
+ const json = (data) => route.fulfill({ json: data });
+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
+ if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: settings.fx });
+ if (url.pathname === "/api/settings") return json(settings);
+ if (url.pathname === "/api/update") {
+ if (ctl.hold) await ctl.hold;
+ return json(ctl.update || { state: "latest", current: "0.1.400" });
+ }
+ if (url.pathname === "/api/usage/quotas") return json([]);
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname.startsWith("/api/")) return json({});
+ if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
+ try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
+ };
+}
+
+const ready = { state: "ready", current: "0.1.400", latest: "0.1.401" };
+
+// every frame, the Version row's height and the line under its name
+const watchRow = (version) => {
+ window.__rows = [];
+ const look = () => {
+ const r = [...document.querySelectorAll("#about .row.pref")].find((r) => r.querySelector(".name")?.textContent === version);
+ if (r && r.offsetParent && !r.dataset.left) window.__rows.push({ h: r.getBoundingClientRect().height, sub: r.querySelector(".who .sub")?.textContent ?? null });
+ if (!window.__stop) requestAnimationFrame(look);
+ };
+ look();
+};
+
+async function open(browser, lang, ctl, width, url) {
+ const errors = [];
+ const page = await (await browser.newContext({ viewport: { width, height: 700 } })).newPage();
+ page.setDefaultTimeout(5000);
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", server(lang, ctl));
+ await watchSettingsReads(page);
+ await page.addInitScript(`(${watchRow})(${JSON.stringify(words[lang].version)})`);
+ await page.goto(url);
+ return { page, errors };
+}
+
+const versionRow = (page, lang) => page.locator("#about .row.pref", { has: page.locator(".name", { hasText: words[lang].version }) }).first();
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ test(engine + ": the Version row and the title bar hold still while the update's state comes in (#4057)", async (t) => {
+ assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ for (const lang of Object.keys(words)) {
+ const w = words[lang];
+
+ await t.test(lang + ": opened cold, the row keeps its line for the answer", async () => {
+ let release;
+ const ctl = { hold: new Promise((go) => (release = go)) };
+ const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
+ await settingsDrawn(page);
+ await page.waitForFunction(() => window.__rows.length > 20);
+ release();
+ const row = versionRow(page, lang);
+ await row.locator(".sub", { hasText: w.latest }).waitFor();
+ await page.evaluate(() => (window.__stop = true));
+ const tall = (await row.boundingBox()).height;
+ const rows = await page.evaluate(() => window.__rows.slice());
+ const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
+ assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px with its answer; ${off.length} of ${rows.length} frames drew it otherwise`);
+ assert.deepEqual(errors, []);
+ await page.context().close();
+ });
+
+ await t.test(lang + ": a state read a minute ago isn't drawn before the answer", async () => {
+ const ctl = {};
+ const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
+ await settingsDrawn(page);
+ const row = versionRow(page, lang);
+ await row.locator(".sub", { hasText: w.latest }).waitFor();
+ const tall = (await row.boundingBox()).height;
+ await page.evaluate(() => show("agents"));
+ // a minute on, a check has downloaded 0.1.401; its read is held
+ let release;
+ ctl.hold = new Promise((go) => (release = go));
+ ctl.update = ready;
+ // the row left on screen is drawn again when Settings is: only the
+ // new row's frames count
+ await page.evaluate((version) => {
+ for (const r of document.querySelectorAll("#about .row.pref")) r.dataset.left = "1";
+ const now = Date.now;
+ Date.now = () => now() + 60e3;
+ window.__rows = [];
+ show("settings");
+ }, w.version);
+ await page.waitForFunction(() => window.__rows.length > 20);
+ release();
+ await row.locator(".sub", { hasText: w.ready }).waitFor();
+ await page.evaluate(() => (window.__stop = true));
+ const rows = await page.evaluate(() => window.__rows.slice());
+ const stale = rows.filter((s) => s.sub === w.latest);
+ assert.equal(stale.length, 0, `"${w.latest}", a minute old, was drawn in ${stale.length} of ${rows.length} frames before "${w.ready}"`);
+ const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
+ assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px; ${off.length} of ${rows.length} frames drew it otherwise`);
+ assert.deepEqual(errors, []);
+ await page.context().close();
+ });
+
+ await t.test(lang + ": the Update pill opens from nothing, the search beside the sidebar sliding with it", async () => {
+ const ctl = {};
+ const { page, errors } = await open(browser, lang, ctl, 1200, "http://magpie.test/?view=settings&tab=about");
+ await settingsDrawn(page);
+ await versionRow(page, lang).locator(".sub", { hasText: w.latest }).waitFor();
+ assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at 1200px");
+ const frames = () => page.evaluate(() => new Promise((go) => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(go)))));
+ await frames();
+ const at = () => page.evaluate(() => $("#setQ").getBoundingClientRect().left);
+ const before = await at();
+ // the pill's opening is held at its first frame, as it is shown
+ ctl.update = ready;
+ await page.evaluate(() => {
+ const b = $("#update");
+ new MutationObserver(() => {
+ if (b.hidden) return;
+ window.__opening = b.getAnimations();
+ for (const a of window.__opening) { a.pause(); a.currentTime = 0; }
+ }).observe(b, { attributes: true, attributeFilter: ["hidden"] });
+ renderUpdateBadge();
+ });
+ await page.waitForFunction(() => !$("#update").hidden && window.__opening);
+ await frames();
+ const first = await at();
+ assert.ok(Math.abs(first - before) <= 1, `the search moved ${before - first}px in the pill's first frame`);
+ await page.evaluate(() => { for (const a of window.__opening) a.finish(); });
+ await frames();
+ const after = await at();
+ assert.ok(before - after > 30, `the pill took its room once open: the search at ${before}, then ${after}`);
+ assert.deepEqual(errors, []);
+ await page.context().close();
+ });
+ }
+ });
+}