From 27c90c8d884eaa9b67f8f66850cd99f9062da95e Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 30 Sep 2026 01:05:38 +0800 Subject: [PATCH] =?UTF-8?q?panel:=20profiles=20open=20from=20Profiles=20at?= =?UTF-8?q?=20the=20Agents=20tab's=20foot,=20on=20its=20left,=20instead=20?= =?UTF-8?q?of=20a=20tab=20of=20their=20own=20(Image=20#65:=20tray=20window?= =?UTF-8?q?=20=E4=B8=AD=E6=96=B9=E6=A1=88=E4=B8=8D=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=B8=AA=E5=8D=95=E7=8B=AC=E7=9A=84=20tab?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=20Agents=20tab=20=E5=B7=A6=E4=B8=8B=E8=A7=92?= =?UTF-8?q?=E6=9C=89=E4=B8=AA=E6=96=B9=E6=A1=88=E5=8D=B3=E5=8F=AF)=20?= =?UTF-8?q?=E2=80=94=20the=20tray=20panel's=20tabs=20are=20Agents=20and=20?= =?UTF-8?q?Routing;=20the=20footer's=20left=20corner,=20on=20the=20Agents?= =?UTF-8?q?=20tab=20only,=20has=20Profiles=20(=E6=96=B9=E6=A1=88)=20with?= =?UTF-8?q?=20how=20many=20there=20are,=20and=20a=20click=20opens=20them?= =?UTF-8?q?=20upward=20over=20the=20list=20as=20a=20popover=20(the=20.pop?= =?UTF-8?q?=20look=20and=20fade,=20reduced=20motion=20kept):=20the=20chips?= =?UTF-8?q?,=20=EF=BC=8B=20Save=20current=20and=20its=20name=20field=20as?= =?UTF-8?q?=20before,=20the=20popover=20scrolling=20within=20itself=20when?= =?UTF-8?q?=20there=20are=20many,=20sized=20between=20the=20tabs=20and=20t?= =?UTF-8?q?he=20footer.=20A=20click=20outside,=20Escape=20(the=20name=20fi?= =?UTF-8?q?eld's=20Escape=20closes=20the=20field=20alone=20first),=20anoth?= =?UTF-8?q?er=20tab=20or=20a=20profile=20applied=20closes=20it;=20the=20li?= =?UTF-8?q?st=20under=20it=20is=20never=20moved.=20A=20remembered=20Profil?= =?UTF-8?q?es=20tab=20opens=20Agents.=20fit()=20no=20longer=20measures=20t?= =?UTF-8?q?he=20profiles.=20Tested:=20panel-profiles.test.cjs=20reworked?= =?UTF-8?q?=20(no=20Profiles=20tab;=20the=20popover=20above=20the=20button?= =?UTF-8?q?=20at=20the=20foot's=20left=20and=20under=20the=20tabs,=20the?= =?UTF-8?q?=20count=20shown;=20scrolling=20to=20=EF=BC=8B=20Save=20current?= =?UTF-8?q?=20inside=20it,=20the=20field=20whole=20and=20nothing=20moving;?= =?UTF-8?q?=20Escape,=20outside=20click,=20Routing=20tab=20and=20applying?= =?UTF-8?q?=20a=20profile=20close=20it;=20Profiles=20only=20on=20Agents)?= =?UTF-8?q?=20and=20old-webkit.test.cjs=20opening=20it=20before=20Save,=20?= =?UTF-8?q?in=20Chromium=20and=20WebKit,=20en=20and=20zh.=20Screenshots=20?= =?UTF-8?q?looked=20at=20in=20light=20and=20dark,=20en=20and=20zh.=20go=20?= =?UTF-8?q?build=20-tags=20nogui=20(and=20GOOS=3Dlinux,=20GOOS=3Dwindows),?= =?UTF-8?q?=20go=20test=20-tags=20nogui=20./...=20and=20the=20GUI=20suite?= =?UTF-8?q?=20pass=20(click-scroll,=20panel-profiles,=20panel-routing=20an?= =?UTF-8?q?d=20routing-kind=20failed=20under=20--test-concurrency=3D4=20an?= =?UTF-8?q?d=20pass=20alone).=20Not=20tried=20in=20the=20real=20Wails=20wi?= =?UTF-8?q?ndow.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.css | 28 ++++++++--- internal/gui/assets/app.js | 49 ++++++++++++++++--- internal/gui/assets/index.html | 2 +- internal/gui/tests/old-webkit.test.cjs | 3 +- internal/gui/tests/panel-profiles.test.cjs | 55 ++++++++++++++++++---- 5 files changed, 113 insertions(+), 24 deletions(-) diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 061a585f5..457b60fe7 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -720,10 +720,9 @@ body.panel .view { padding-top: 2px; } .ptabs button.on { color: var(--fg); font-weight: 550; } .ptabs button[hidden] { display: none; } .ptabs em { font-style: normal; font-weight: 400; color: var(--faint); font-variant-numeric: tabular-nums; } -body.panel[data-ptab="usage"] :is(#agents, .profiles, #panelRouting), -body.panel[data-ptab="routing"] :is(#agents, .profiles, #panelQuota), -body.panel[data-ptab="profiles"] :is(#agents, #panelQuota, #panelRouting), -body.panel[data-ptab="agents"] :is(.profiles, #panelQuota, #panelRouting) { display: none; } +body.panel[data-ptab="usage"] :is(#agents, #panelRouting), +body.panel[data-ptab="routing"] :is(#agents, #panelQuota), +body.panel[data-ptab="agents"] :is(#panelQuota, #panelRouting) { display: none; } /* ---- the panel's agents: one quiet line each, opened in place ------------ */ /* icon · name · model · effort · chevron, the last three in columns of their @@ -800,10 +799,25 @@ body.panel .agent-fold-cap { padding-left: 12px; } /* "Show 9 more", the list's last line, where the names start */ body.panel .agent-more { justify-content: flex-start; gap: 6px; padding: 9px 14px; } -/* ---- the panel's profiles tab ---------------------------------------------- */ +/* ---- the panel's profiles: Profiles at the Agents tab's foot, left, opens + them over the list, upward from it ------------------------------------------ */ +.prof-btn { display: inline-flex; align-items: center; gap: 4px; margin-left: -7px; } +.prof-btn em { font-style: normal; color: var(--faint); font-variant-numeric: tabular-nums; } +.prof-btn[aria-expanded="true"] { color: var(--fg); background: var(--pill-hover); } +body.panel:not([data-ptab="agents"]) .prof-btn { display: none; } +body.panel .foot .status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +body.panel .profiles { display: none; } /* the chips a line of their own; a name field opened goes beside the button */ -body.panel .profiles { flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 0; } -body.panel .profiles > .label { display: none; } +body.panel .profiles.open { + display: flex; position: fixed; z-index: 30; left: 8px; width: min(360px, calc(100vw - 16px)); min-height: 0; + flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 8px; padding: 10px; overflow-y: auto; overscroll-behavior: contain; + background: var(--pop-bg); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); + border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); + transform-origin: 24px bottom; --pop-dy: 6px; + animation: pop-fade .18s ease-out, pop-in .42s cubic-bezier(.16, 1, .3, 1); +} +@media (prefers-reduced-motion: reduce) { body.panel .profiles.open { animation: pop-fade .12s ease-out; } } +body.panel .profiles > .label { display: block; flex: 1 1 100%; padding: 0 2px; } body.panel .profiles .chips { flex: 1 1 100%; flex-wrap: wrap; } body.panel .profiles .chips .hint { white-space: normal; line-height: 1.4; padding: 0 4px; color: var(--muted); } body.panel .profiles.naming .chips .hint { display: none; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 5db51ea10..3fd64160e 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -440,6 +440,7 @@ function renderProfiles() { $(".profiles > .chip-input")?.remove(); // a name field open goes with the list it was for $(".profiles").classList.remove("naming"); $("#save").textContent = t("+ Save current"); + $("#profN").textContent = state.profiles.length || ""; if (!state.profiles.length) chips.append(el("span", "hint", t("none yet · save the setup to switch back in one click"))); for (const p of state.profiles) { const c = el("button", "chip"); @@ -953,7 +954,7 @@ function fit(extra = 0, glide) { const body = document.body, tab = body.dataset.ptab; delete body.dataset.ptab; // extra is only ever the agents' (a row opening, the scroll unrolling) - const tallest = Math.max($("#agents").offsetHeight + extra, $(".profiles").offsetHeight, $("#panelQuota").offsetHeight, $("#panelRouting").offsetHeight); + const tallest = Math.max($("#agents").offsetHeight + extra, $("#panelQuota").offsetHeight, $("#panelRouting").offsetHeight); if (tab) body.dataset.ptab = tab; const h = $(".top").offsetHeight + $("#ptabs").offsetHeight + tallest + $(".foot").offsetHeight + 4; if (h === fit.last) return; @@ -1604,6 +1605,7 @@ async function profileAction(action, name, update) { state = data; renderAgents(); if (action === "use") { + closeProfiles(); // the agents, as they are now, in sight let msg = t(data.changed === 1 ? "{name} applied · {n} setting changed" : "{name} applied · {n} settings changed", { name, n: data.changed }); const lib = data.library; if (lib?.missing?.length) msg += " · " + t("skipped, no longer in the Library: {names}", { names: lib.missing.map((m) => m.replace(/^\w+:/, "")).join(", ") }); @@ -5221,16 +5223,49 @@ function planSpan(q) { return s; } -// The tray panel is four tabs over the one page: the agents, the allowances -// of every subscription and key (the "usage" tab, as it was named before), -// the gateway's latest requests (routing.js draws those) and the saved -// profiles. The tab is remembered. +// The tray panel is three tabs over the one page: the agents, the allowances +// of every subscription and key (the "usage" tab, as it was named before) +// and the gateway's latest requests (routing.js draws those). The saved +// profiles open from Profiles at the Agents tab's foot, over the list (a tab +// of their own was one too many). The tab is remembered. +const profBtn = $("#profBtn"), profBox = $(".profiles"); +function placeProfiles() { + if (!profBox.classList.contains("open")) return; + const r = profBtn.getBoundingClientRect(), top = $("#ptabs").getBoundingClientRect().bottom; + profBox.style.bottom = Math.round(innerHeight - r.top + 6) + "px"; + profBox.style.maxHeight = Math.max(120, Math.round(r.top - 6 - top - 4)) + "px"; +} +function openProfiles() { + profBox.classList.add("open"); + profBtn.setAttribute("aria-expanded", "true"); + placeProfiles(); +} +function closeProfiles() { + if (!profBox.classList.contains("open")) return; + profBox.classList.remove("open"); + profBtn.setAttribute("aria-expanded", "false"); + const f = $(".profiles > .chip-input"); + if (f) closeSave(f); +} +if (mode === "panel") { + profBtn.hidden = false; + document.body.append(profBox); // over the page, not in the list's scroll + profBtn.onclick = () => profBox.classList.contains("open") ? closeProfiles() : openProfiles(); + document.addEventListener("mousedown", (e) => { + if (profBox.classList.contains("open") && !profBox.contains(e.target) && !profBtn.contains(e.target)) closeProfiles(); + }, true); + // the name field's Escape is its own (it stops there) + document.addEventListener("keydown", (e) => { if (e.key === "Escape" && profBox.classList.contains("open")) { closeProfiles(); profBtn.focus({ preventScroll: true }); } }); + addEventListener("resize", placeProfiles); +} let panelTab = "agents"; try { panelTab = localStorage.getItem("magpie.panelTab") || "agents"; } catch {} function setPanelTab(tab) { const tabs = $("#ptabs"); - // no usage to show, no tab for it - if (tabs.querySelector(`[data-ptab="${tab}"]`)?.hidden) tab = "agents"; + // no usage to show, no tab for it (nor for profiles: they open from the foot) + const b = tabs.querySelector(`[data-ptab="${tab}"]`); + if (!b || b.hidden) tab = "agents"; + closeProfiles(); panelTab = tab; try { localStorage.setItem("magpie.panelTab", tab); } catch {} document.body.dataset.ptab = tab; diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 01fd94a50..89eddecdf 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -47,7 +47,6 @@ -
@@ -243,6 +242,7 @@