From 917a3657789c7bef4e2dd25b4857d7f1df454772 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 11 Oct 2026 19:42:33 +0800 Subject: [PATCH] gui: opening the Usage page or the tray panel's Allowances reads the allowances now, once in 30s (#1588, qq666666qq) On Windows the tray panel's Allowances tab, and the window brought back on Usage, showed the reading magpie kept until "Read the allowances again now" was pressed: picking the panel's tab and the panel shown again only loaded usage/quotas without ?asked=1, which hands back the backend's cache, and so did the window coming back to the front on the Usage page. Opening the allowances is now asking to see them (quotasOpened), as Refresh now is and as #1518 counts the Usage page opened: - the window: Usage from the nav (as before), the Overview tab picked, and the window back to the front on the Overview; - the tray panel: the Allowances tab picked, the panel brought up on it (focus / visibility), and a menu bar cell clicked (panelQuotaFocus). A panel page loaded while it is put away (hidden or without focus) doesn't ask, so a panel prepared at login sends nothing with allowance reads at "When I ask". An asked read makes the backend read every account again (AskUsage clears the caches; only Claude has its own 30s floor), so an opening within 30s of the last asked read (QUOTAS_OPEN_GAP) sends an ordinary read instead: switching tabs and back, focus and visibilitychange both firing, focus-follows-mouse don't reach the vendors again. Reads stay one at a time: an opening during an ordinary read goes after it (loadQuotas, unchanged). Refresh now still asks every time; the timed refresh is unchanged and never asks. Written against main from qq666666qq's fork patch (qq666666qq/magpie#1), which asked on every tab click and every return without a gap; this keeps their entries and adds the gap, the Overview tab, and the hidden-panel guard. Run: new allowance-open-read.test.cjs (Chromium and WebKit, en and zh, panel at 360px): passes; red on the old app.js (the panel's Allowances never asks; the window re-asks on every nav click), red with QUOTAS_OPEN_GAP = 0, and red with the window-return line removed. The GUI tests touching the allowances (every test naming usage/quotas, the Usage view or the panel's Allowances tab) in both engines, and go test -tags nogui ./internal/gui. No Go changes. Not tried in the native Windows tray. Of the GUI run (3164 tests, load ~120-230), the 8 failures passed when their files were run again, except library-mcp-tool-switch in WebKit, which fails the same with main's app.js (76db4c6c2): filed as #1609. Rebased onto f6e1e98ee; the new test, claude-usage-asked, panel-usage, panel-arrange, click-scroll and ./internal/gui run again after it. --- docs/subsystems/gui-shell.md | 1 + docs/subsystems/providers-accounts.md | 2 +- internal/gui/assets/app.js | 33 ++- .../gui/tests/allowance-open-read.test.cjs | 192 ++++++++++++++++++ .../gui/tests/claude-usage-asked.test.cjs | 5 +- 5 files changed, 225 insertions(+), 8 deletions(-) create mode 100644 internal/gui/tests/allowance-open-read.test.cjs diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index d5da4de49..30755dd72 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -153,6 +153,7 @@ retry after a failed read. See `TestRecentCallBodiesOnDemand` and - A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). - There are no native `