From 10da2936da1f5e45dca2bdeedd1b9ae3b5298a75 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 2 Oct 2026 05:06:53 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20Settings=20is=20a=20page=20per=20part,?= =?UTF-8?q?=20under=20a=20tab=20each,=20the=20part=20kept=20in=20the=20add?= =?UTF-8?q?ress=20(#471:=20Settings=20is=20one=20long=20scroll=20of=20some?= =?UTF-8?q?=2045=20rows=20in=209=20sections)=20=E2=80=94=20the=20page=20no?= =?UTF-8?q?w=20opens=20with=20a=20tab=20list=20in=20the=20warm-ups'=20look?= =?UTF-8?q?=20(role=3Dtablist,=20a=20tab=20each=20with=20aria-controls/ari?= =?UTF-8?q?a-labelledby):=20General=20(appearance,=20language,=20text=20si?= =?UTF-8?q?ze,=20the=20icons,=20model=20names,=20login,=20Dock,=20session?= =?UTF-8?q?=20terminal),=20Usage=20(the=20menu=20bar's=20usage,=20refresh,?= =?UTF-8?q?=20logos,=20what=20usage=20shows,=20currency,=20number=20units,?= =?UTF-8?q?=20the=20two=20alerts,=20then=20the=20warm-up=20and=20check-in?= =?UTF-8?q?=20tabs),=20Network=20and=20sharing=20(proxy,=20local=20network?= =?UTF-8?q?),=20Models=20(images,=20web=20search),=20Privacy,=20Observabil?= =?UTF-8?q?ity,=20Sync=20and=20backup,=20About;=20the=20part=20picked=20sh?= =?UTF-8?q?ows=20its=20rows=20alone.=20Every=20row,=20its=20id=20and=20wha?= =?UTF-8?q?t=20it=20saves=20are=20as=20they=20were;=20the=20duplicate=20he?= =?UTF-8?q?ading=20of=20a=20one-section=20part=20and=20the=20Preferences?= =?UTF-8?q?=20heading=20are=20gone.=20The=20part=20is=20kept=20as=20=3Fvie?= =?UTF-8?q?w=3Dsettings&tab=3D=20(dropped=20on=20any=20other=20view)?= =?UTF-8?q?,=20so=20a=20reload=20or=20a=20link=20lands=20there,=20and=20re?= =?UTF-8?q?membered=20(magpie.settingsTab)=20for=20Settings=20opened=20aga?= =?UTF-8?q?in=20without=20one,=20as=20the=20tray's=20window/main=3Fview=3D?= =?UTF-8?q?settings;=20an=20unknown=20one=20falls=20back=20to=20it.=20A=20?= =?UTF-8?q?part=20whose=20rows=20are=20all=20hidden=20on=20this=20system?= =?UTF-8?q?=20has=20no=20tab,=20and=20one=20picked=20falls=20back=20to=20t?= =?UTF-8?q?he=20first=20shown.=20The=20arrows,=20Home=20and=20End=20move?= =?UTF-8?q?=20along=20the=20tabs,=20one=20in=20the=20Tab=20order;=20a=20cl?= =?UTF-8?q?ick=20on=20a=20tab=20moves=20nothing=20on=20the=20page,=20the?= =?UTF-8?q?=20tabs=20staying=20where=20they=20were;=20a=20pill=20drawn=20w?= =?UTF-8?q?hile=20its=20part=20was=20hidden=20has=20its=20thumb=20put=20un?= =?UTF-8?q?der=20its=20pick=20when=20shown=20(the=20warm-ups'=20fix,=20now?= =?UTF-8?q?=20shared).=20The=20tabs=20wrap=20to=20a=20line=20more=20when?= =?UTF-8?q?=20they=20don't=20fit=20(English=20in=20the=20560x420=20window,?= =?UTF-8?q?=20at=20110=20and=20125%,=20a=20phone),=20no=20left-border=20st?= =?UTF-8?q?ripe.=20The=20click=20hold=20also=20holds=20a=20click=20not=20y?= =?UTF-8?q?et=20held=20before=20taking=20the=20next=20(keys=20pressed=20wi?= =?UTF-8?q?thin=20a=20frame=20on=20a=20tab=20list=20whose=20part=20shrank?= =?UTF-8?q?=20to=20the=20window:=20the=20second=20click=20was=20taken=20at?= =?UTF-8?q?=20the=20clamped=20top=20and=20the=20page=20stayed=20there).=20?= =?UTF-8?q?New=20strings=20General=20and=20Network=20and=20sharing=20are?= =?UTF-8?q?=20in=20i18n.js=20(=E5=B8=B8=E8=A7=84,=20=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E4=B8=8E=E5=85=B1=E4=BA=AB).=20Tests=20that=20reach=20a=20row?= =?UTF-8?q?=20now=20open=20or=20click=20its=20part:=20api-key-theme,=20cur?= =?UTF-8?q?rency,=20gateway-caller-keys,=20gateway-connect-keys,=20lan-doc?= =?UTF-8?q?ker,=20number-units,=20otel,=20redact-rule-row,=20s3-sync,=20se?= =?UTF-8?q?arch-api,=20settings-groups,=20sync-other-kind,=20tray-inuse,?= =?UTF-8?q?=20tray-logos,=20tray-usages,=20update-check,=20update-hide,=20?= =?UTF-8?q?usage-alert,=20webdav-settings-refresh,=20whats-new;=20those=20?= =?UTF-8?q?needing=20a=20scrolled=20page=20wheel=20a=20shorter=20window=20?= =?UTF-8?q?or=20in=20smaller=20steps,=20as=20a=20part=20is=20shorter=20tha?= =?UTF-8?q?n=20the=20whole=20page=20was.=20settings-sections.test.cjs=20(C?= =?UTF-8?q?hromium,=20WebKit,=20en,=20zh)=20fails=20without=20the=20change?= =?UTF-8?q?=20(10=20of=2010).=20go=20vet=20./internal/...,=20go=20build=20?= =?UTF-8?q?-tags=20nogui=20(darwin,=20GOOS=3Dlinux),=20GOOS=3Dwindows=20go?= =?UTF-8?q?=20build,=20go=20test=20-tags=20nogui=20./...=20pass=20(TestAcc?= =?UTF-8?q?ountProxy=20as=20on=20main);=20settings-sections,=20settings-gr?= =?UTF-8?q?oups,=20click-scroll,=20old-webkit,=20text-size=20and=20every?= =?UTF-8?q?=20settings=20test=20listed=20above=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.css | 9 + internal/gui/assets/app.js | 108 ++++++-- internal/gui/assets/i18n.js | 3 + internal/gui/assets/index.html | 257 ++++++++++-------- internal/gui/tests/README.md | 19 +- internal/gui/tests/api-key-theme.test.cjs | 6 +- internal/gui/tests/currency.test.cjs | 3 + .../gui/tests/gateway-caller-keys.test.cjs | 2 + .../gui/tests/gateway-connect-keys.test.cjs | 4 + internal/gui/tests/lan-docker.test.cjs | 6 +- internal/gui/tests/number-units.test.cjs | 2 + internal/gui/tests/otel.test.cjs | 4 +- internal/gui/tests/redact-rule-row.test.cjs | 2 +- internal/gui/tests/s3-sync.test.cjs | 9 +- internal/gui/tests/search-api.test.cjs | 2 +- internal/gui/tests/settings-groups.test.cjs | 37 +-- internal/gui/tests/settings-sections.test.cjs | 251 +++++++++++++++++ internal/gui/tests/sync-other-kind.test.cjs | 1 + internal/gui/tests/tray-inuse.test.cjs | 1 + internal/gui/tests/tray-logos.test.cjs | 1 + internal/gui/tests/tray-usages.test.cjs | 3 +- internal/gui/tests/update-check.test.cjs | 8 +- internal/gui/tests/update-hide.test.cjs | 2 +- internal/gui/tests/usage-alert.test.cjs | 4 +- .../tests/webdav-settings-refresh.test.cjs | 1 + internal/gui/tests/whats-new.test.cjs | 2 +- 26 files changed, 574 insertions(+), 173 deletions(-) create mode 100644 internal/gui/tests/settings-sections.test.cjs diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index b147aa6f8..fa0c1f127 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -1910,6 +1910,15 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .warm-tabs button.on { color: var(--fg); background: var(--pill); } .warm-tabs button[hidden] { display: none; } .warm-panes { margin-bottom: 8px; } +/* the page's parts (#471): a tab each at the top in the same look, a line + more when they don't fit across (a narrow window, a larger text size), + the part picked alone under them */ +#view-settings .set-head { height: auto; min-height: 26px; flex: none; } +.set-tabs { flex-wrap: wrap; row-gap: 2px; min-width: 0; } +.set-tabs button { flex: none; white-space: nowrap; } +.set-page { flex: none; } +.set-page[hidden] { display: none; } +.set-page > .list:not(:last-child) { margin-bottom: 8px; } .row.pref { min-height: 50px; padding: 8px 12px 8px 14px; gap: 14px; } .row.pref .who { flex: 1 1 auto; } .row.pref .sub { margin-top: 2px; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index c67bc8a47..275a3bf62 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -10712,29 +10712,27 @@ function setWarmTab(tab, remember) { b.setAttribute("aria-selected", String(on)); b.tabIndex = on ? 0 : -1; $("#" + list).hidden = !on; - // a pill drawn while its card was hidden measured nothing: its thumb is - // put under the option picked, still, once the card is shown - if (on) for (const th of $("#" + list).querySelectorAll(".segs > .thumb")) { - const opt = th.parentElement.querySelector(":scope > .on"); - if (!opt || parseFloat(th.style.width) === opt.offsetWidth) continue; - th.classList.add("still"); - th.style.transform = `translateX(${opt.offsetLeft}px)`; - th.style.width = opt.offsetWidth + "px"; - void th.offsetWidth; - th.classList.remove("still"); - } + if (on) thumbsUnderPicks($("#" + list)); } } -{ - const tabs = $("#warmTabs"); - tabs.onclick = (e) => { - const b = e.target.closest("button[data-warm]"); - if (b) setWarmTab(b.dataset.warm, true); - }; - // the arrows, Home and End move along the tabs, as a tab list's do: the - // tab reached is clicked, so the page is held as for a click +// a pill drawn while its card was hidden measured nothing: its thumb is +// put under the option picked, still, once the card is shown +function thumbsUnderPicks(box) { + for (const th of box.querySelectorAll(".segs > .thumb")) { + const opt = th.parentElement.querySelector(":scope > .on"); + if (!opt || !opt.offsetParent || parseFloat(th.style.width) === opt.offsetWidth) continue; + th.classList.add("still"); + th.style.transform = `translateX(${opt.offsetLeft}px)`; + th.style.width = opt.offsetWidth + "px"; + void th.offsetWidth; + th.classList.remove("still"); + } +} +// A tab list's keys: the arrows, Home and End move along its shown tabs, +// and the tab reached is clicked, so the page is held as for a click +function tabKeys(tabs, sel) { tabs.onkeydown = (e) => { - const shown = [...tabs.querySelectorAll("button[data-warm]:not([hidden])")]; + const shown = [...tabs.querySelectorAll(sel + ":not([hidden])")]; const i = shown.indexOf(document.activeElement); if (i < 0) return; const j = { ArrowLeft: i - 1, ArrowRight: i + 1, Home: 0, End: shown.length - 1 }[e.key]; @@ -10746,6 +10744,69 @@ function setWarmTab(tab, remember) { b.click(); }; } +{ + const tabs = $("#warmTabs"); + tabs.onclick = (e) => { + const b = e.target.closest("button[data-warm]"); + if (b) setWarmTab(b.dataset.warm, true); + }; + tabKeys(tabs, "button[data-warm]"); +} + +// The Settings page is a page per part (#471: one long scroll of some 45 +// rows): a tab for each over them, in the warm-ups' look, its rows alone +// under it. The part is kept in the address (?view=settings&tab=privacy) so +// a reload comes back to it, and remembered for the window opened again. +// A part with no row to show here (every one hidden on this system) has no +// tab. A click on a tab, like every click, leaves the page where it is: the +// tabs at the top stay where they were and the part comes in under them. +const SET_TABS = ["general", "usage", "network", "models", "privacy", "otel", "sync", "about"]; +let setTab = "general"; +try { const k = localStorage.getItem("magpie.settingsTab"); if (SET_TABS.includes(k)) setTab = k; } catch {} +let setShown = setTab; // the part shown: the one picked, or the first there +// A part has a tab while a row of it shows: one not hidden itself nor within +// it (a service's card under the warm-ups' tabs counts, picked or not). A +// part not drawn yet, with no rows at all, keeps its tab. +const partShows = (page) => { + const rows = [...page.querySelectorAll(".row")]; + return !rows.length || rows.some((r) => { + for (let n = r; n && n !== page; n = n.parentElement) if (n.hidden && !n.matches('[role="tabpanel"]')) return false; + return true; + }); +}; +function setSetTab(tab, remember) { + if (remember) { + setTab = tab; + try { localStorage.setItem("magpie.settingsTab", tab); } catch {} + } + for (const id of SET_TABS) $("#setTab-" + id).hidden = !partShows($("#setPage-" + id)); + if (!SET_TABS.includes(tab) || $("#setTab-" + tab).hidden) tab = SET_TABS.find((id) => !$("#setTab-" + id).hidden) || "general"; + for (const id of SET_TABS) { + const b = $("#setTab-" + id), on = id === tab; + b.classList.toggle("on", on); + b.setAttribute("aria-selected", String(on)); + b.tabIndex = on ? 0 : -1; + $("#setPage-" + id).hidden = !on; + if (on) thumbsUnderPicks($("#setPage-" + id)); + } + setShown = tab; + $("#setTabs").setAttribute("aria-label", t("Settings")); + if (view === "settings") syncURL(); +} +{ + const tabs = $("#setTabs"); + tabs.onclick = (e) => { + const b = e.target.closest("button[data-set]"); + if (b) setSetTab(b.dataset.set, true); + }; + tabKeys(tabs, "button[data-set]"); + // opened on a part (a reload, a link): that part, and remembered + if (mode === "window" && params.get("view") === "settings" && SET_TABS.includes(params.get("tab"))) { + setTab = params.get("tab"); + try { localStorage.setItem("magpie.settingsTab", setTab); } catch {} + } + setSetTab(setTab); +} function renderSettings() { const s = prefs; @@ -10856,6 +10917,8 @@ function renderSettings() { repo.title = "github.com/yetone/magpie"; repo.onclick = () => api("open", { url: "https://github.com/yetone/magpie" }).catch(() => {}); row(t("Community"), t("questions, ideas and feedback, on Discord or GitHub"), "", join, repo); + // the parts' tabs, one gone whose rows are all hidden here + setSetTab(setTab); } function renderSessionTerminal(s, keep) { @@ -12038,6 +12101,10 @@ addEventListener("click", (e) => { purposeUntil = 0; // what came before the click (Space pressed on a button, a tremble) is no scroll const v = e.target.closest?.(".view"); if (!v || v.hidden) { held = null; return; } + // a click before a frame has held the one before it (a tab list's keys + // pressed in quick turn) holds that one first: the page it shrank is put + // back, so this one is taken where the reader left it, not at the top + if (held?.v === v) hold(held); const chain = []; const from = e.target.closest?.("[data-unrolls]")?.parentElement || e.target; for (let n = from; n && n !== v; n = n.parentElement) { @@ -12085,6 +12152,7 @@ function syncURL() { const q = new URLSearchParams(location.search); if (view === "agents") q.delete("view"); else q.set("view", view); if (view === "providers" && typeof editing === "string") q.set("edit", editing); else q.delete("edit"); + if (view === "settings") q.set("tab", setShown); else q.delete("tab"); const s = q.size ? "?" + q : location.pathname; if (s !== location.search) history.replaceState(null, "", s); } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 71ced1793..f7882d3e4 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1366,6 +1366,9 @@ const I18N = { // settings "Preferences": "偏好", + // the Settings page's parts, a tab each + "General": "常规", + "Network and sharing": "网络与共享", "Session terminal": "会话终端", "Used by the terminal button in Sessions; only apps registered for .command files appear": "用于会话列表中的终端按钮;仅显示已注册处理 .command 文件的应用", "System default ({name})": "系统默认({name})", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 138e897a1..a93108137 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -211,128 +211,153 @@
-
Preferences
-
-
-
Appearance
Light or dark, or whatever the system is showing
Follows the Omarchy theme, as picked in Omarchy's menu
-
-
-
-
Language
Applies at once, no restart
-
-
-
-
Text size
-
-
-
-
Tray icon
What clicking magpie’s icon in the menu bar or tray opens
-
-
- -
-
Usage in the menu bar
-
-
- - -
-
Usage shows
How much of each window is used, or how much is left, on the Usage page, the panel and the menu bar
-
-
-
-
Currency
-
-
- -
-
Usage alert
-
-
-
-
Low balance alert
-
-
-
-
Provider in model names
Agents’ lists put each model’s provider after its name, or not after names you set
-
-
-
-
Open at login
Start magpie in the tray when you log in, so agents find the gateway from the start
-
-
- - -
-
Proxy
-
-
-
-
- - - +
+ + + + + + + +
-
-
-
-
Warm up on reset
-
+
+
+
+
Appearance
Light or dark, or whatever the system is showing
Follows the Omarchy theme, as picked in Omarchy's menu
+
+
+
+
Language
Applies at once, no restart
+
+
+
+
Text size
+
+
+
+
Tray icon
What clicking magpie’s icon in the menu bar or tray opens
+
+
+ +
+
Provider in model names
Agents’ lists put each model’s provider after its name, or not after names you set
+
+
+
+
Open at login
Start magpie in the tray when you log in, so agents find the gateway from the start
+
+
+ +
-
-
Daily warm-up
-
+
+
+
+
+
Usage in the menu bar
+
+
+ + +
+
Usage shows
How much of each window is used, or how much is left, on the Usage page, the panel and the menu bar
+
+
+
+
Currency
+
+
+ +
+
Usage alert
+
+
+
+
Low balance alert
+
+
-
-
-
-
Warm up on reset
-
+
+ + + +
+
+
+
+
Warm up on reset
+
+
+
+
Daily warm-up
+
+
-
-
Daily warm-up
-
+
+
+
Warm up on reset
+
+
+
+
Daily warm-up
+
+
-
-
-
-
Daily check-in
-
+
+
+
Daily check-in
+
+
-
-
-
Local network
-
-
Images
-
-
Web search
-
-
Privacy
-
-
Observability
-
-
Sync and backup
-
-
About
-
+
+ +
+
+
+
Proxy
+
+
+
+
Local network
+
+
+
+
Images
+
+
Web search
+
+
+
+
+
+
+
+
+
+
+
+
+
+