Files
magpie/internal/gui/assets/panelarrange.js
T
yetone 286e3b6d5f gui: the tray panel's Usage tab puts a vendor's account first from its count (RealZeroP27 on X)
RealZeroP27 asked to switch the Codex account in use from the menu bar
panel's quota page, not from the Providers page.

A vendor group with several accounts on the panel's Usage tab now draws
its count as a button (the count and a chevron). It opens the app menu
(openProtoMenu) with the accounts the provider editor can put first, the
first one ticked, and Manage accounts… at the foot, which opens the
window's Providers page. Picking one does what the editor's Make first
or Use does, through the same code: putFirst, now shared by the editor
and the panel. Kept signed in to one, that is provider/arrange with the
account first in the order; otherwise login/switch. The first account's
card gets a small tick. It works for any subscription with several
signed-in accounts (Codex, Claude, a plugin's), not only Codex.
Setup-token, access-only and lapsed accounts are left out, as in the
editor; kept signed in, so are paused or off ones. A vendor with one
account that can be first keeps its plain count.

The panel's provider list (panelAccts) is now also read when the Usage
tab has two accounts of one vendor, one read at a time. The menu reads
a fresh list first when only the kept one is drawn. pluginSubs falls
back to that list, since the panel has no window list (it threw on
null before).

Budget: the menu is in panelfirst.js, loaded when the count is pressed,
and the Allowances tab's arranging (panelArrange, hidePanelUsage) moved
out to panelarrange.js, loaded when Arrange is pressed. That pays for
the rest with no comments cut and no raise (#5918); the core is at
1,533,604 of 1,533,802. old-webkit's lazy list names both files.

Run (mote, at this change on origin/main 662546e78; rebased after onto
55b0d7c24, which changes only internal/gateway):
- GUI, chromium and webkit: panel-usage-first-account (5 languages x
  440/360px), panel-switch-accounts, panel-arrange, grip-inset,
  old-webkit, i18n-keys: 227 ok, 1 red: old-webkit's "the styles hold
  up in Safari 15.0" on main's .side-foot:has() from d374168d0, filed
  as #5919, the same at main.
- go test -run Budget ./internal/gui/ at this head: ok. The whole
  package before the rebase: the only red is
  TestGatewayModeStatsNameTheGatewaySessions, run at 00:22 local, which
  is #5690 (red in the first hour of a local day), untouched here.
- go vet ./internal/gui for darwin, GOOS=linux -tags nogui, GOOS=windows:
  ok. gofmt -l: clean.
- Before the rebase, 21 GUI files were run at this change and at main
  6a253f8af; the reds they share are the same on main under load. The
  two head-only reds (panel-switch-accounts' "reads the list once", a
  null box while the group redrew) were fixed here.

Broken by hand:
- The new test is red on origin/main's assets (no .pq-pick).
- putFirst with the kept branch turned off sends login/switch in the
  kept case: the kept test goes red.
- Dropping !l.accessOnly puts the access-only account in the menu: the
  menu's list check goes red.

Not tried: the whole GUI suite, a real account switch from the real
panel, the real Linux (WebKitGTK) app.
2026-11-10 16:37:19 +08:00

78 lines
3.4 KiB
JavaScript

// The tray panel's arranging of its Allowances tab, loaded when Arrange is
// pressed (app.js's arrange button), so it weighs nothing on the core.
// The Allowances tab's arranging (H20 on Discord): a row a subscription,
// in the order the Usage page's cards have, its logo the handle to move it
// (drag, or Alt+arrows) and a pill to hide it from this tab or show it
// again. Hiding is the panel's alone; routing and the rest still use it.
window.panelArrange = function panelArrange(subs) {
const g = el("div", "pq-group pq-arranging");
const head = el("div", "pq-gh");
head.append(el("span", "pq-gn", t("Arrange")));
const done = el("button", "pq-mode pq-done", t("Done"));
done.type = "button";
done.onclick = () => { panelArranging = false; renderPanelQuota(); };
head.append(done);
g.append(head, el("p", "pq-anote", t("Hiding is for this panel only: routing, the Usage page and the menu bar still use what's hidden. The order is the Usage page's too.")));
const hidden = new Set(state.settings?.panelUsageHidden || []);
const list = el("div", "pq-alist");
const seen = new Set();
for (const q of subs) {
if (seen.has(q.provider)) continue;
seen.add(q.provider);
const off = hidden.has(q.provider);
const row = el("div", "pq-arow" + (off ? " put-away" : ""));
row.dataset.key = q.provider;
const h = el("button", "ag-handle pq-ahandle");
h.type = "button";
h.setAttribute("aria-label", t("Arrange {agent}", { agent: q.name }));
h.title = t("Drag to reorder · Alt+arrow keys to move");
h.append(icon(q.icon || "generic"));
h.onkeydown = (e) => {
const step = { ArrowUp: -1, ArrowLeft: -1, ArrowDown: 1, ArrowRight: 1 }[e.key];
if (!e.altKey || !step) return;
e.preventDefault();
moveUsage(q.provider, usageKeys().indexOf(q.provider) + step);
$(`#panelQuota .pq-arow[data-key="${CSS.escape(q.provider)}"] .pq-ahandle`)?.focus(NO_SCROLL);
};
h.onpointerdown = (e) => {
if (usageArranging) return;
usageArranging = dragCards(e, h, row, list, [...list.children], (to) => moveUsage(q.provider, to), () => {
usageArranging = false;
if (usageRenderPending) { usageRenderPending = false; renderQuotas(); }
});
};
const pill = el("button", "pq-more pq-show", t(off ? "Show" : "Hide"));
pill.type = "button";
pill.setAttribute("aria-pressed", String(!off));
pill.title = t(off ? "Show {name} in this panel" : "Hide {name} from this panel", { name: q.name });
pill.onclick = () => hidePanelUsage(q.provider, !off);
row.append(h, el("span", "pq-aname", q.name), off ? el("span", "pq-hidden", t("Hidden")) : "", pill);
list.append(row);
}
g.append(list);
return g;
};
// hidePanelUsage hides a subscription from the panel's Allowances tab, or
// shows it again: drawn at once, put back if the save fails.
async function hidePanelUsage(key, hide) {
const prev = state.settings;
const cur = (prev.panelUsageHidden || []).filter((k) => k !== key);
const panelHidden = hide ? [...cur, key] : cur;
state.settings = { ...prev, panelUsageHidden: panelHidden };
const again = () => {
renderPanelQuota();
$(`#panelQuota .pq-arow[data-key="${CSS.escape(key)}"] .pq-show`)?.focus(NO_SCROLL);
};
again();
try {
const s = await api("usage/arrange", { panelHidden });
state.settings = { ...state.settings, panelUsageHidden: s.panelUsageHidden || [] };
} catch (e) {
state.settings = prev;
again();
statusErr(e);
}
}