Commit Graph
3 Commits
Author SHA1 Message Date
yetone 2ba044aa66 gui: the Mac panel's page is told when Wails hides it, so it follows Settings' units (blrbrzkj)
blrbrzkj on Discord: Settings said ¥ 人民币 and 中文(万 / 亿), while the
tray panel's Usage tab still showed ≈$7.18 and 16M.

On the Mac a page in an ordered-out window keeps drawing, so magpie tells
it when it is hidden (hideWebview) and shown (showWebview), and the page
reloads its state, settings included, on the shown signal. The panel is
mostly closed by a click elsewhere, which Wails' HideOnFocusLost does
with a plain Hide, and by Escape (HideOnEscape), likewise. The page was
never told it was hidden there, so the shown signal was a no-op
(magpieWindowVisibility returns early when it was never told otherwise),
and the panel kept the currency and number units it was first drawn
with until magpie restarted.

sayWailsHides (windowvisibility.go), on the panel: on the Mac the page is
told on WindowLostFocus, as hideWebview tells it, and Escape hides the
panel through hideWebview. Other systems are unchanged: WebView2 and
WebKitGTK mark a hidden window's page hidden themselves.

Tests:
- TestPanelHiddenByWailsMarksPageOutOfSight (AppKit, darwin): makes the
  real panel (h.makePanel), closes it by a WindowLostFocus event and by
  the Escape key binding, as Wails does, shows it with showWebview, and
  checks the page saw itself hidden and marked. The probe page now
  reports what it saw when it is told it is shown, so a native hidden
  event before the told one can't be the record it sends.
- panel-units-follow.test.cjs: the page half. A panel open on its Usage
  tab in $ and K/M; Settings picks ¥ and 万 / 亿; hidden and shown, the
  panel re-reads the state and shows ≈¥185, 15.4 亿 (億 in zh-TW) and a
  万 axis, then back to ≈$26.40 and 1.54B. zh, en, zh-TW, ja, de;
  Chromium and WebKit.

Run on mote (macOS 27.2), at this tree:
- go test -run 'TestClosingWindowMarksPageOutOfSight|TestPanelHiddenByWailsMarksPageOutOfSight' ./internal/gui/: ok
- go vet ./internal/gui/, GOOS=linux go vet -tags nogui, GOOS=windows go vet: ok; gofmt -l: nothing
- node --test panel-units-follow, window-visibility, number-units: 20/20

Broken by hand:
- sayWailsHides(w) not called: the AppKit test times out with no hidden
  report.
- only its Escape binding removed: red, "hidden=true marked=false
  play=running".
- the page's visibilitychange without loadBack (a copy of the assets):
  panel-units-follow red, "shown again, the panel reads the state again".
- The panel test written to show without a told hide (the old Mac path)
  was 0/12 on the unchanged page, which is how the cause was found.

Not tried: the real tray panel by hand on a Mac (the AppKit test makes
the real panel window but no status item); blrbrzkj's system isn't
known, and on Windows and Linux the page is marked hidden by the webview
itself, so this changes nothing there.
2026-11-04 16:32:55 +08:00
yetoneandpipi dfe868a1eb gui: only a Mac page is told it is hidden, and focus tells it it is back (#4293)
On top of pipi-1997's 9704a0901, which is kept as written.

Off the Mac the panel is shown again by Wails' ToggleWindow, which never
ran showWebview. With hideWebview telling every page it was hidden, an
Escape-closed panel on Windows or Linux would have come back with
document.hidden true, its polling stopped for good. WebView2 and
WebKitGTK mark a hidden window's page hidden themselves, so only the Mac
is told now (pageHiddenJSOn), and a page that takes focus marks itself
visible whichever path showed it.

The page side is the same behaviour in fewer bytes (729 for 1,237), in a
try as before. The core scripts are 1,533,802 bytes, over 1,533,073 at
origin/main ace58117a; the budget is raised to that, with no room added,
and says why.

Run on mote (macOS 27.2):
- TestClosingWindowMarksPageOutOfSight passes. With hideWebview's signal
  taken out by hand it fails: "while hidden the page saw hidden=true
  state=\"hidden\" marked=false play=\"running\"". So on 27.2 WebKit
  does mark the page hidden by itself; the CSS animations still run,
  which is what the reporter's sample shows (updateRendering from the
  RemoteLayerTreeDrawingArea timer). The reporter's 27.0 is not
  tried here.
- TestPageToldHiddenOnTheMacOnly, red with the GOOS check taken out.
- go test ./internal/gui: ok except TestMainWindowCorners (#3949) and
  TestColdTurnsTaken (#4510, reopened with the output); neither touches
  window visibility.
- GOOS=windows go vet ./internal/gui; GOOS=linux -tags nogui vet: ok.
- gofmt -l: clean.
GUI on WSL magpie-desktop (another session's suite was on mote): the
whole suite (make test-ui) ran past its 3500s bound at load ~90 with no
result. The eight Routing files it showed red, plus window-visibility,
were then run at this head and at origin/main df0320156, one after the
other at load ~55: here 28 of 91 red, at main 31 of 89, the same tests
(rule ⋯, request opens, row swap, request model, idle frame, back in
sight), all already filed (#4600, #4585). window-visibility passes in
Chromium and WebKit.
After the rebase onto ace58117a, on mote: the budget tests,
TestClosingWindowMarksPageOutOfSight and TestPageToldHiddenOnTheMacOnly
ok; window-visibility, routing-idle-frame and routing-flood 23 of 23 in
Chromium and WebKit (the last two red on WSL under load).

Not run: the WebContent CPU after closing a real window. mote has no
display, so a shown window's WebContent used 0.01s in 5s there and
there was nothing to compare; the 26-42% is the reporter's measurement
on an M1 Pro.

Co-authored-by: pipi <zhuangpipi01@gmail.com>
2026-11-01 17:28:30 +08:00
pipi f06551c277 gui: a closed window's page is told it is out of sight
A macOS orderOut hides the NSWindow but can leave its WKWebView document
visible. The Routing page's frame loop and SVG animations therefore kept
running in a closed window (20-40% Web Content CPU; reopening and closing
returned it to 0%).

Tell the page before every app-window hide and again on show. Compose that
signal with WebKit's own hidden state, and pause CSS animations while out of
sight.

Verified with:
- go test ./internal/gui -run '^(TestCoreScriptBudget|TestClosingWindowMarksPageOutOfSight|TestClosingHidesShownAccounts|TestPanelCloseHidesIt|TestPanelJoinsFullScreenSpaces)$' -count=1
- node --test internal/gui/tests/window-visibility.test.cjs (Chromium and WebKit)
- the new JS test against v0.1.2049's app.js: it times out without the bridge
- the new AppKit test with hideMain calling Hide directly: it times out without the visibility signal
- go vet ./internal/gui
- GOOS=linux CGO_ENABLED=0 go vet -tags nogui ./internal/gui
- GOOS=windows CGO_ENABLED=0 go vet ./internal/gui

The full GUI package still has unrelated environment failures in
TestProxyCheckSaysAProxyPassedBy and TestMainWindowCorners on this macOS 27
setup.
2026-11-01 17:28:30 +08:00