gui: a Back in the title bar after a link into a setting, and a lit row keeps its corners

The owner (11-10): "点击设置链接跳转到设置页面之后,最好有一个返回按钮来返回到上一页,
类似于浏览器的返回按钮。" A link into a setting (openSettingsAt: the Usage
page's and Routing's Settings ›, the Gateway page's, a provider's, Plugins ›
Built-in's) and Plugins › Built-in's link to a page now leave a chevron
Back in the title bar, before the crumb (beside the sidebar) or after the
brand (the header's tabs), named "Back to {page}". It goes to that page:
the provider that was open, or Settings' tab and search. One step, like
a browser's first; going to another page by hand drops it. fitTop counts
it as the header's lead, so the tabs keep clear of it.

And (the owner, 11-10): "绿色边框的四个圆角会被切掉,这个很丑的". A lit row's
inset ring was square inside the list's rounded clip, so the first and
last rows lost their ring's corners. A lit row is rounded as the list is
inside its border (11px; 10px in the panel, whose lists have no border).

New test settings-back.test.cjs: Usage's Settings › lights the row with
rounded corners, Back shows with its name, fits, overlaps nothing in the
title bar, and goes back; Routing's the same; a page picked by hand drops
Back. Every language, Chromium and WebKit, 1100 and 420 wide.

The core's script budget pays for Back with five long comments in app.js
cut to a line each (Back's own, Built-in's rows, the refresh, its spin's
stop, a growing part's hold), no raise; TestCoreScriptBudget ok on mote.

Run on mote: settings-back, i18n-keys, settings-places, title-bar-tools:
53 of 54; the red is title-bar-tools' known WebKit flake (#2740, #4716),
red 1 run in 3 alone, the same at the base.
Broken by hand: without renderBack in show, settings-back red; without the
11px radius, red with row 0 vs list 11.
Not tried: the real app window.
This commit is contained in:
yetone
2026-11-10 02:12:18 +08:00
parent 1eebd1ff3c
commit b72256b599
5 changed files with 158 additions and 25 deletions
+4
View File
@@ -931,6 +931,10 @@ body.window .field.solo { grid-column: auto; }
.field .chev { color: var(--faint); display: inline-flex; margin-left: auto; padding-left: 1px; }
.field:hover .chev, .field.open .chev { color: var(--muted); }
.field.flash, .subscription-card.flash, .pq-card.flash, .row.pref.flash { animation: flash 1.2s ease-out; }
/* a lit row's ring keeps its corners: the list's rounded clip cut them off
(the owner, 11-10), so it is rounded as the list is inside its border */
.row.pref.flash { border-radius: 11px; }
body.panel .row.pref.flash { border-radius: 10px; }
@keyframes flash { 0%, 35% { box-shadow: inset 0 0 0 1px var(--green); background: var(--green-soft); } 100% {} }
/* ---- usage ---------------------------------------------------------------- */
+45 -25
View File
@@ -81,6 +81,7 @@ let state = { agents: [], profiles: [], catalog: "", settings: {} };
let prefs = null; // the settings page: theme, lang, version, dir, gateway
let providers = null; // { providers, presets, gateway }
let view = "agents";
let backTo = null, jumpNext = false; // Back (jumpFrom)
let showAllAgents = false; // the agents no one has set anything on, folded away
let showHiddenAgents = false; // under them, the ones hidden by hand: a fold of their own, shut until asked
let period = "today"; // usage window
@@ -23080,11 +23081,8 @@ addEventListener("resize", () => {
relaid.observe(v);
for (const c of v.children) if (!c.classList.contains("view-room")) relaid.observe(c);
});
// A part that grows or shrinks as it plays (the agents' scroll unrolling
// above the button that unrolls it) is held again as soon as it is laid out,
// before it's painted: a frame's loop sees it only as the frame before left
// it, a frame late, so what was clicked would tremble by as much as it grew
// in a frame.
// A part that grows as it plays is held again once laid out, before paint,
// or what was clicked trembles a frame late
const heldSizes = new ResizeObserver(() => { if (held) hold(held); });
function keepHeld() {
const h = held;
@@ -23141,6 +23139,8 @@ addEventListener("scroll", () => import("./scrollends.js"), { capture: true, pas
let settingsLoad = Promise.resolve(); // show()'s read of Settings, for openSettingsAt
async function show(v) {
const jump = jumpNext;
jumpNext = false;
// a built-in page a plugin's page replaces (magpie.page.replaces) opens that
v = magpie.replacing?.(v) || v;
// a page gateway mode leaves out (a link to it, an address kept) opens Providers
@@ -23169,11 +23169,13 @@ async function show(v) {
// the page left lets go of what was only for this visit
magpie.call(view, "leave");
}
if (v !== view && !jump) backTo = null;
view = v;
renderBack();
window.hideAccounts?.page();
// the page the reader leaves is the one the window opens on next (keptView)
if (mode === "window") { try { localStorage.setItem("magpie.lastView", v); } catch { /* not kept */ } }
const title = magpie.page(v)?.title ?? ({ agents: "Agents", providers: "Providers", plugins: "Plugins", settings: "Settings" })[v];
const title = pageName(v);
$("#pageTitle").dataset.en = title;
$("#pageTitle").textContent = t(title);
if (mode === "window") {
@@ -23268,12 +23270,8 @@ function applyFeatures(list) {
setSetTab(setTab);
navSubs();
}
// Plugins › Built-in: a row each, its name, what it is and a switch, kept
// in plugins.yml (builtins.go). One in use can't be switched off, and says
// what uses it; a plugins.yml that doesn't parse says so, and none can be
// switched until it is fixed. done gets the list after a switch. One on
// with settings has them under it, a row each, drawn from their schema
// (kernel.js's ui.form) and saved as each is changed.
// Plugins › Built-in: a row and a switch each (plugins.yml, builtins.go);
// one in use can't be switched off; its settings under it (ui.form)
function renderBuiltins(box, list, done) {
const broken = list.find((f) => f.broken)?.broken;
const rows = list.flatMap((f) => {
@@ -23342,7 +23340,7 @@ function featGo(line, f) {
// not to settings hidden while it is off (Observability, warm-ups)
if (tab && (f.on || !$(row)?.closest("[data-feature]"))) to.push([t("Settings") + " › " + $("#setTab-" + tab).textContent, (e) => openSettingsAt(e, tab, row + " .row")]);
const nav = f.on && $(`#nav [data-view="${f.page || f.opens}"]`);
if (nav && !nav.hidden) to.push([nav.textContent, () => nav.click()]);
if (nav && !nav.hidden) to.push([nav.textContent, () => { jumpFrom(nav.dataset.view); nav.click(); }]);
for (const [say, go] of to) {
const b = el("button", "link", say);
b.type = "button";
@@ -23381,11 +23379,42 @@ function openSettings() {
closeAgentMenu();
show("settings");
}
// Back to the page a settings link came from (the owner, 11-10)
function jumpFrom(to) {
if (to === view) return;
backTo = { view, edit: view === "providers" && typeof editing == "string" ? editing : null,
tab: view === "settings" ? setShown : null, q: view === "settings" ? $("#setQ").value : "" };
jumpNext = true;
}
function pageName(v) {
return magpie.page(v)?.title ?? ({ agents: "Agents", providers: "Providers", plugins: "Plugins", settings: "Settings" })[v];
}
function renderBack() {
const b = $("#navBack"), on = !!backTo && backTo.view !== view;
if (on) {
const say = t("Back to {page}", { page: t(pageName(backTo.view)) });
b.dataset.tt = say;
b.setAttribute("aria-label", say);
}
if (b.hidden === !on) return;
b.hidden = !on;
fitTop();
}
$("#navBack").onclick = async () => {
const b = backTo;
if (!b) return;
if (b.edit) await openProvider(b.edit);
else if (!await show(b.view)) return;
if (!b.tab) return;
setSetTab(b.tab);
if (b.q) { $("#setQ").value = b.q; searchSettings(b.q); }
};
// openSettingsAt: Settings at a row, in sight and lit; e is the click
async function openSettingsAt(e, tab, row) {
const go = scrollOnPurpose(e, 3000);
closeProtoMenu();
closeAgentMenu();
jumpFrom("settings");
if (!await show("settings")) return;
if (setQuery) { $("#setQ").value = ""; searchSettings(""); }
setSetTab(tab, true);
@@ -23399,11 +23428,7 @@ async function openSettingsAt(e, tab, row) {
}
$("#prefs").onclick = () => { openSettings(); $("#prefs").blur(); };
// The header's refresh reads again what the page shown draws (#844): on
// Agents it looks for the agents on this computer again (one just installed
// or removed, or its settings changed outside magpie), on Usage it reads the
// usage and the allowances now, and elsewhere it refreshes the model lists.
// A newer magpie is looked for on its own, and from Settings › About's Check.
// The header's refresh reads again what the page shown draws (#844)
function refreshKind() {
if (mode === "panel") return { agents: "agents", usage: "allowances", stats: "requests" }[panelTab] || "models";
return { agents: "agents", usage: "usage" }[view] || "models";
@@ -23458,12 +23483,7 @@ $("#sync").onclick = async () => {
status(kind === "models" ? t("Sync failed: {e}", { e: e.message }) : e.message, "err");
} finally {
b.blur();
// stop at the end of a turn, not wherever the reply caught it (#16).
// The turn itself is told to be the last, so it ends on the compositor's
// clock: waiting for animationiteration and then dropping the class
// jumped the icon back by however far it had turned while the page was
// busy drawing the reply — the twitch at the end of every refresh.
// The svg's drawing turns, not the svg (app.css), one animation a part.
// stop at the end of a turn, on the compositor's clock (#16)
const spins = b.querySelector("svg").getAnimations({ subtree: true });
const stop = () => b.classList.remove("spin");
if (spins.length && spins.every((a) => a.effect?.updateTiming)) {
@@ -23530,7 +23550,7 @@ function fitTop() {
// the buttons sit against the padding; under a page zoom (the text size)
// their edge can measure a hair past it, which isn't running off (#457)
if (a.right > top.getBoundingClientRect().right - parseFloat(getComputedStyle(top).paddingRight) + 0.5) return false;
const lead = brand.offsetParent ? brand : $("#sideToggle");
const lead = $("#navBack").offsetParent ? $("#navBack") : brand.offsetParent ? brand : $("#sideToggle");
const left = lead.offsetParent ? lead.getBoundingClientRect().right
: top.getBoundingClientRect().left + parseFloat(getComputedStyle(top).paddingLeft);
if (!nav?.offsetParent) return left + 8 <= a.left;
+4
View File
@@ -2979,6 +2979,7 @@ const I18N = {
"Undo": "撤销",
"Sync by itself": "自动同步",
"Back up by itself": "自动备份",
"Back to {page}": "返回{page}",
"1 week": "1 周",
"6 hours": "6 小时",
"Back up now": "立即备份",
@@ -7740,6 +7741,7 @@ const I18N = {
"Undo": "復原",
"Sync by itself": "自動同步",
"Back up by itself": "自動備份",
"Back to {page}": "返回{page}",
"1 week": "1 週",
"6 hours": "6 小時",
"Back up now": "立即備份",
@@ -12511,6 +12513,7 @@ const I18N = {
"Undo": "取り消す",
"Sync by itself": "自動同期",
"Back up by itself": "自動バックアップ",
"Back to {page}": "{page}に戻る",
"1 week": "1 週間",
"6 hours": "6 時間",
"Back up now": "今すぐバックアップ",
@@ -17293,6 +17296,7 @@ const I18N = {
"Undo": "Rückgängig",
"Sync by itself": "Selbst synchronisieren",
"Back up by itself": "Selbst sichern",
"Back to {page}": "Zurück zu {page}",
"1 week": "1 Woche",
"6 hours": "6 Stunden",
"Back up now": "Jetzt sichern",
+2
View File
@@ -63,6 +63,8 @@
<span>magpie</span>
</div>
<h1 class="sr-only" id="pageTitle" data-t>Agents</h1>
<!-- back to the page a link into a setting came from (app.js jumpFrom) -->
<button type="button" class="icon nav-back" id="navBack" hidden data-tt style="--wails-draggable:no-drag"><svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true"><path d="M10 3.25 5.25 8 10 12.75" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<div class="crumb" id="crumb" aria-hidden="true" hidden></div>
<nav class="seg" id="nav" aria-label="Main navigation" data-ta style="--wails-draggable:no-drag">
<span class="nav-gl" data-t>Work</span>
+103
View File
@@ -0,0 +1,103 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A link into a setting (the Usage page's and the Routing page's Settings ›)
// leaves a Back in the title bar, as a browser's, to the page it came from;
// going to another page by hand drops it (the owner, 11-10). The row it lit
// keeps its ring's corners: the list's rounded clip cut them off. Every
// language, Chromium and WebKit, at 1100 and 420 wide, nothing past the
// window's edge. 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 assets = path.resolve(__dirname, "../assets");
function server(lang, web) {
const cur = {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", textSize: 100,
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", login: false, trayUsage: "", trayUsageEvery: 3,
visionModels: [], imageGenModels: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
return async (route) => {
const req = route.request(), url = new URL(req.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:${web},textSize:100};` });
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", textSize: 100 }, fx: cur.fx });
if (url.pathname === "/api/settings") return json(cur);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/providers") return json({ providers: [] });
if (url.pathname === "/api/usage/quotas") return json([{ provider: "codex", name: "Codex", icon: "openai", plan: "Plus", user: "dev.one@example.com", windows: [{ name: "5 hours", used: 20 }] }]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
if (url.pathname.startsWith("/api/")) return json({});
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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const fits = (page) => page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}: Back goes to where a link into a setting came from`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(6000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; errors.push(e.message); });
await page.route("**/*", server(lang, false));
await page.goto("http://magpie.test/?view=usage");
const back = page.locator("#navBack");
const go = page.locator("#quotaHead #usageToSet");
await go.waitFor();
assert.equal(await back.isVisible(), false, "no Back before a jump");
await go.click();
const lit = page.locator("#view-settings #setPage-usage #quotaLeftRow.flash");
await lit.waitFor();
// the ring is rounded as the list is inside its border
const r = await lit.evaluate((row) => {
const l = getComputedStyle(row.closest(".list"));
return { row: parseFloat(getComputedStyle(row).borderTopLeftRadius), list: parseFloat(l.borderTopLeftRadius) - parseFloat(l.borderTopWidth) };
});
assert.ok(r.row >= r.list - 0.5, "the lit row's corners follow the list's: " + JSON.stringify(r));
await back.waitFor();
const say = await page.evaluate(() => t("Back to {page}", { page: t(magpie.page("usage").title) }));
assert.equal(await back.getAttribute("aria-label"), say);
assert.ok(await fits(page), "fits with Back");
// Back sits clear of the tabs and the title bar's icons
const clear = await page.evaluate(() => {
const b = document.querySelector("#navBack").getBoundingClientRect();
return [...document.querySelectorAll(".top #nav, .top .actions, .top .brand, .top #crumb")].filter((e) => e.offsetParent)
.every((e) => { const o = e.getBoundingClientRect(); return o.right <= b.left + 0.5 || o.left >= b.right - 0.5; });
});
assert.ok(clear, "Back overlaps nothing in the title bar");
await back.click();
await page.locator("#view-usage").waitFor({ state: "visible" });
assert.equal(await page.locator("#view-settings").isVisible(), false);
assert.equal(await back.isVisible(), false, "gone once back");
// Routing's Settings ›, then a page picked by hand: no Back
await page.goto("http://magpie.test/?view=routing");
await page.locator("#rtToSet").click();
await page.locator("#view-settings #routeList .row.flash").waitFor();
await back.waitFor();
await back.click();
await page.locator("#rtToSet").waitFor();
await page.locator("#rtToSet").click();
await back.waitFor();
await page.evaluate(() => show("plugins"));
await page.locator("#view-plugins").waitFor({ state: "visible" });
assert.equal(await back.isVisible(), false, "another page picked drops Back");
assert.deepEqual(errors, []);
});
}
}
}