gui: an icon button at work shows the spinner, not its glyph turning
wiirhan on X (tweet 2123287273043378671): "资源库--技能--更新技能的loading
状态为啥是直接转箭头?" A Library skill's Update turned its own up arrow
while the fetch ran (.lib-icon.busy svg { animation: lib-spin }), so the
busy state looked like a broken arrow, not like work.
glyphBusy (app.js) puts the spinner's arc, CLI_SPIN, the one saving() and
a CLI's update pill turn, in place of the button's glyph while it works,
and puts the glyph back when it is done or fails. The arc turns at .8s,
and under prefers-reduced-motion it stands still.
Siblings: an agent row's Apply again and Restart (.ag-fix) turned their
reapply arrow the same way, and now take glyphBusy too. Kept as they are:
the refresh arrows that re-read data (quota-refresh, usage-refresh,
rt-read, #sync, pu-again). Their glyph is a turning arrow, so turning it
says what it does, and the owner tuned them in #16.
TestCoreScriptBudget: app and core budgets +228. glyphBusy is packed to
its shortest form, and renderAgents and the Library rows draw it on every
window, so there is no page to move it to.
skill-update-feedback.test.cjs waited for the svg itself to animate. It
now waits for the arc's path, with the row's actions still in view.
Run (mote, via mote-run):
- busy-glyph-spinner.test.cjs (new): chromium + webkit, en/zh/zh-TW/ja/de,
1100px and 420px (reduced motion at 420). Green 22/22. Red 22/22 on
origin/main f534245f1's assets. Restart's glyphBusy broken by hand:
chromium 11/11 red.
- go test ./internal/gui: ok at the rebased head (budget included).
- Whole GUI suite at 59e0421f4, beside other sessions' runs (load 20-60):
29713 tests, 28689 pass, 1024 fail in 122 files. One red was this
change's: skill-update-feedback, fixed above. The other 121 files were
run again at head 0f0827c28: 118 still red (2300 tests, 1021 fail). The
same 118 files at origin/main f534245f1: 2254 tests, 1017 fail, the same
files red. Subtest counts differ by one or two in account-cap,
context-cap, desktop-tiers, menu-input-scroll, rest-try-now and
tray-cell-click, both ways; none touches an icon button.
provider-base-as-typed was red once at head and passes when rerun.
Filed already: #6975 (most of the 118), #6782, #7016, #7097, #7131,
#7132, #7101, #7100, #7242, #7033, #7083, #7046, #6234.
Not tried: the real app (Wails/WebKitGTK). The change is an svg swap with
a transform animation the spinner already uses there.
This commit is contained in:
@@ -849,7 +849,9 @@ body.panel #agents > .row .ag-handle::before { left: -8px; }
|
||||
.ag-open .field.ag-who .ok { order: 2; }
|
||||
.ag-who .ok { display: none; flex: none; align-items: center; gap: 3px; color: var(--green); font-weight: 600; }
|
||||
.ag-who.done .ok { display: inline-flex; }
|
||||
/* busy: app.js glyphBusy has put the spinner's arc in place of the glyph */
|
||||
.ag-fix.busy svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .8s linear infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .ag-fix.busy svg > * { animation: none; } }
|
||||
/* what has to listen at an address no agent reaches magpie by (#1013): long addresses wrap, and it can be copied */
|
||||
.drift-why { overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
|
||||
/* the agent's CLI on its name's line (#202): its version faint, and a quiet
|
||||
|
||||
@@ -2115,13 +2115,13 @@ function appRestart(a) {
|
||||
e.stopPropagation();
|
||||
if (!(await confirmRestart(a.name))) return;
|
||||
go.disabled = true;
|
||||
go.classList.add("busy");
|
||||
glyphBusy(go, true);
|
||||
try {
|
||||
state = await api("agents/restart/" + a.id, {});
|
||||
renderAgents();
|
||||
status(t("{agent} restarted", { agent: a.name }));
|
||||
} catch (err) {
|
||||
if (go.isConnected) { go.disabled = false; go.classList.remove("busy"); }
|
||||
if (go.isConnected) { go.disabled = false; glyphBusy(go, false); }
|
||||
status(tNotice(err.message), "err");
|
||||
}
|
||||
};
|
||||
@@ -2506,7 +2506,7 @@ async function keepAgent(a) {
|
||||
|
||||
// reapplyAgent writes what magpie set on the agent into its config again.
|
||||
async function reapplyAgent(a, btn) {
|
||||
btn?.classList.add("busy");
|
||||
glyphBusy(btn, true);
|
||||
try {
|
||||
state = await api("agents/reapply/" + a.id, {});
|
||||
renderAgents();
|
||||
@@ -2514,7 +2514,7 @@ async function reapplyAgent(a, btn) {
|
||||
const msg = t("{agent} goes through magpie again", { agent: a.name });
|
||||
saidOk(msg);
|
||||
} catch (e) {
|
||||
btn?.classList.remove("busy");
|
||||
glyphBusy(btn, false);
|
||||
statusErr(e);
|
||||
}
|
||||
}
|
||||
@@ -2529,6 +2529,18 @@ const cliBusy = new Set(); // the ones being updated now
|
||||
const CLI_UP = "M8 2.5v8M4.5 7 8 10.5 11.5 7M3.5 13.5h9";
|
||||
const CLI_SPIN = "M13.5 8a5.5 5.5 0 1 1-5.5-5.5";
|
||||
|
||||
// glyphBusy shows an icon button at work with the spinner the others turn
|
||||
// (saving, a CLI's update): its glyph is put aside for the arc and comes
|
||||
// back when it is done. A glyph turning on itself said nothing but that
|
||||
// it was turning (a skill's update arrow went round, @wiirhan on X).
|
||||
function glyphBusy(b, on) {
|
||||
const g = b?.querySelector("svg");
|
||||
if (!g) return;
|
||||
b.classList.toggle("busy", on);
|
||||
if (on) b.held ||= (g.replaceWith(svg(CLI_SPIN, g.getAttribute("width"))), g);
|
||||
else if (b.held) g.replaceWith(b.held), b.held = 0;
|
||||
}
|
||||
|
||||
function cliTag(a) {
|
||||
const box = el("span", "ag-cli");
|
||||
// its settings are here, its CLI isn't: uninstalled, its folder left
|
||||
|
||||
@@ -8342,13 +8342,14 @@ magpie.plugin("library", (ctx) => {
|
||||
if (!gone && (s.kind === "github" || s.kind === "git" || s.origin)) {
|
||||
const u = button("", "lib-icon", async (e, b) => {
|
||||
if (s.edited) return confirmUpdateEdited(s);
|
||||
// spinning, with the row's actions kept in view while the fetch
|
||||
// runs; then what came of it: updated, nothing new, or the error
|
||||
b.classList.add("busy");
|
||||
// the spinner in place of its arrow, with the row's actions kept in
|
||||
// view while the fetch runs; then what came of it: updated,
|
||||
// nothing new, or the error
|
||||
glyphBusy(b, true);
|
||||
b.parentElement?.classList.add("busy");
|
||||
await change("skills/update", { name: s.name }, (res) => res?.current?.includes(s.name)
|
||||
? t("{name} is already up to date", { name: s.name }) : t("{name} is updated", { name: s.name }));
|
||||
b.classList.remove("busy");
|
||||
glyphBusy(b, false);
|
||||
b.parentElement?.classList.remove("busy");
|
||||
});
|
||||
u.append(svg(GLYPH.up, 13, 1.5));
|
||||
|
||||
@@ -416,10 +416,9 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
.lib-icon { width: 26px; height: 26px; padding: 0; display: inline-grid; place-items: center; }
|
||||
.lib-rowacts.busy { opacity: 1; }
|
||||
.lib-icon.busy, .lib-icon.busy:disabled { opacity: 1; color: var(--muted); }
|
||||
.lib-icon.busy svg { animation: lib-spin .8s linear infinite; }
|
||||
@keyframes lib-spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .lib-icon.busy svg { animation: lib-pulse 1.2s ease infinite alternate; } }
|
||||
@keyframes lib-pulse { to { opacity: .35; } }
|
||||
/* busy: app.js glyphBusy has put the spinner's arc in place of the glyph */
|
||||
.lib-icon.busy svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .8s linear infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .lib-icon.busy svg > * { animation: none; } }
|
||||
|
||||
/* the skill finder */
|
||||
.lib-install { margin-bottom: 4px; }
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,155 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// @wiirhan on X: "资源库--技能--更新技能的loading状态为啥是直接转箭头?" A
|
||||
// skill's Update in the Library turned its own up arrow round and round
|
||||
// while the fetch ran, which reads as a joke, not as work under way. An icon
|
||||
// button at work now shows the spinner every other button turns (saving, a
|
||||
// CLI's update: CLI_SPIN's arc) in place of its glyph, and gets its glyph
|
||||
// back when it is done. The same for an agent row's Restart, whose circular
|
||||
// arrow turned the same way. Held answers keep each button at work while it
|
||||
// is looked at: the arc is there, the glyph is not, it turns at 0.9s a turn
|
||||
// or faster, and with reduced motion it stands still. Chromium and WebKit,
|
||||
// en, zh, zh-TW, ja and de, wide and narrow. No backend: the API is faked.
|
||||
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 { strings } = require("./strings.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, process.env.MAGPIE_ASSETS || "../assets");
|
||||
const SPIN = "M13.5 8a5.5 5.5 0 1 1-5.5-5.5"; // app.js CLI_SPIN
|
||||
const UP = "M8 12.5v-9 M4.5 7 8 3.5 11.5 7"; // the library's GLYPH.up
|
||||
const REAPPLY = "M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3.25h-3.25"; // app.js REAPPLY
|
||||
const HOME = "/Users/wiirhan";
|
||||
const lib = {
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [{ id: "claude", name: "Claude Code", icon: "", skills: `${HOME}/.claude/skills`, mcp: `${HOME}/.claude.json` }],
|
||||
instructions: { agents: [] }, servers: [], foundServers: [], foundSkills: [], projects: [], problems: [],
|
||||
skills: [{ name: "pdf", description: "Reads PDFs", kind: "github", agents: ["claude"], source: "https://github.com/owner/repo/tree/main/pdf" }],
|
||||
};
|
||||
const days = (n) => new Date(Date.now() - n * 86400e3).toISOString();
|
||||
const workbuddy = {
|
||||
id: "workbuddy", name: "WorkBuddy", icon: "generic", path: "/fixture/models.json", wired: true, appRestart: { since: days(1) },
|
||||
fields: [{ key: "model", label: "model", value: "deepseek-v4", options: [{ value: "deepseek-v4", label: "DeepSeek V4", ref: "deepseek/deepseek-v4", note: "DeepSeek · via magpie" }] }],
|
||||
};
|
||||
|
||||
let I18N;
|
||||
const tr = (lang, key, vars = {}) => {
|
||||
const s = lang === "en" ? key : I18N[lang][key];
|
||||
assert.equal(typeof s, "string", `${lang} has no ${JSON.stringify(key)}`);
|
||||
return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
|
||||
};
|
||||
|
||||
// held: the paths whose answer waits until the test lets it go
|
||||
function serve(lang, held) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data, status = 200) => route.fulfill({ status, json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [workbuddy], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/library") return json(lib);
|
||||
if (url.pathname === "/api/library/skills/update") {
|
||||
await new Promise((go) => held.set("update", go));
|
||||
return json({ ...lib, result: { changed: ["claude"] } });
|
||||
}
|
||||
// the restart fails, so its button stays to show its glyph back
|
||||
if (url.pathname.startsWith("/api/agents/restart/")) {
|
||||
await new Promise((go) => held.set("restart", go));
|
||||
return json({ error: "WorkBuddy is still open" }, 409);
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
if (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: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// what the button draws and how it turns: its paths, and each running
|
||||
// animation that rotates, with its turn's length and how often it repeats
|
||||
// (a colour or opacity transition is not a turn)
|
||||
const look = (loc) => loc.evaluate((b) => ({
|
||||
paths: [...b.querySelectorAll("svg path")].map((p) => p.getAttribute("d")),
|
||||
turns: b.getAnimations({ subtree: true }).filter((a) => a.effect.getKeyframes().some((f) => /rotate|matrix/.test(f.transform || ""))).map((a) => {
|
||||
const tm = a.effect.getComputedTiming();
|
||||
return { duration: tm.duration, iterations: tm.iterations, on: a.effect.target.tagName.toLowerCase() };
|
||||
}),
|
||||
}));
|
||||
|
||||
function atWork(seen, reduce, what) {
|
||||
assert.deepEqual(seen.paths, [SPIN], `${what} at work draws ${JSON.stringify(seen.paths)}, not the spinner alone`);
|
||||
if (reduce) return assert.deepEqual(seen.turns, [], `${what} turns with reduced motion`);
|
||||
const spins = seen.turns;
|
||||
assert.equal(spins.length, 1, `${what}: ${JSON.stringify(seen.turns)}`);
|
||||
assert.equal(spins[0].on, "path", `${what} turns its whole svg, not the arc inside it`);
|
||||
assert.ok(spins[0].duration <= 900, `${what} turns once in ${spins[0].duration}ms`);
|
||||
assert.equal(spins[0].iterations, Infinity);
|
||||
}
|
||||
|
||||
const sideways = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": an icon button at work shows the spinner, not its glyph turning", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
I18N = strings().I18N;
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const [width, reduce] of [[1100, false], [420, true]]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
await t.test(`${lang} at ${width}px${reduce ? ", reduced motion" : ""}`, async () => {
|
||||
const held = new Map(), errors = [];
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: reduce ? "reduce" : "no-preference" });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, held));
|
||||
|
||||
// the Library's skill row: Update, at work and then done
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
const row = page.locator("#view-library .lib-row").filter({ has: page.locator(".name", { hasText: /^pdf$/ }) });
|
||||
await row.waitFor();
|
||||
const up = row.locator(".lib-rowacts .lib-icon").first();
|
||||
assert.deepEqual((await look(up)).paths, [UP], "the row's first action is not Update");
|
||||
await row.hover();
|
||||
await up.click();
|
||||
await page.waitForFunction(() => document.querySelector("#view-library .lib-rowacts .lib-icon.busy"));
|
||||
await page.waitForFunction(() => document.querySelector("#view-library").getAttribute("aria-busy") === "true");
|
||||
assert.equal(held.size, 1, "Update posted nothing");
|
||||
atWork(await look(up), reduce, "a skill's Update");
|
||||
// the row's actions stay in view while Update works (they fade in on hover, so wait out the fade)
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector("#view-library .lib-rowacts")).opacity === "1");
|
||||
assert.ok(await sideways(page) <= 1, "the page scrolls sideways");
|
||||
held.get("update")();
|
||||
await page.locator("#status").filter({ hasText: tr(lang, "{name} is updated", { name: "pdf" }) }).waitFor();
|
||||
const back = row.locator(".lib-rowacts .lib-icon").first();
|
||||
assert.deepEqual(await look(back), { paths: [UP], turns: [] }, "Update didn't get its arrow back");
|
||||
|
||||
// an agent row's Restart, the same
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
const go = page.locator('.row.agent[data-id="workbuddy"] .ag-restart');
|
||||
await go.waitFor();
|
||||
assert.deepEqual((await look(go)).paths, [REAPPLY]);
|
||||
await go.click();
|
||||
await page.locator("dialog.action-confirm[open] button.primary").click();
|
||||
await page.waitForFunction(() => document.querySelector(".ag-restart.busy"));
|
||||
atWork(await look(go), reduce, "Restart");
|
||||
assert.equal((await go.textContent()).trim(), tr(lang, "Restart"));
|
||||
assert.ok(await sideways(page) <= 1, "the page scrolls sideways");
|
||||
held.get("restart")();
|
||||
await page.waitForFunction(() => document.querySelector("#status").classList.contains("err"));
|
||||
await page.waitForFunction(() => !document.querySelector(".ag-restart").disabled);
|
||||
assert.deepEqual(await look(go), { paths: [REAPPLY], turns: [] }, "Restart didn't get its glyph back");
|
||||
assert.deepEqual(errors, []);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// zhexuanliuoutl1 on X: updating a skill from GitHub (hugohe3/ppt-master) said
|
||||
// nothing while it ran. The row's Update button now spins until the fetch is
|
||||
// done, and the toast says what came of it: updated, already up to date, or
|
||||
// the error. In English and Chinese, in Chromium and WebKit. No backend: the
|
||||
// nothing while it ran. The row's Update button now shows the spinner until
|
||||
// the fetch is done, and the toast says what came of it: updated, already up
|
||||
// to date, or the error. In English and Chinese, in Chromium and WebKit. No backend: the
|
||||
// API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
@@ -103,8 +103,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const status = async () => (await page.locator("#status").textContent()).trim();
|
||||
|
||||
await press(page, btn);
|
||||
// held: the button turns, the row's actions stay in view
|
||||
await page.waitForFunction(() => document.querySelector(".lib-skill .lib-rowacts.busy button.lib-icon.busy svg")?.getAnimations().some((a) => a.playState === "running"));
|
||||
// held: the spinner's arc turns in place of the arrow (@wiirhan on X:
|
||||
// the arrow itself went round), the row's actions stay in view
|
||||
await page.waitForFunction(() => document.querySelector(".lib-skill .lib-rowacts.busy button.lib-icon.busy svg path")?.getAnimations().some((a) => a.playState === "running"));
|
||||
await page.mouse.move(0, 0);
|
||||
// (its fade-out, if it were going, is under .14s: a state, not a wait)
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector(".lib-rowacts.busy")).opacity === "1");
|
||||
|
||||
Reference in New Issue
Block a user