Commit Graph
4 Commits
Author SHA1 Message Date
yetone 1d5b5dc2da gui: the panel's visibility test takes only a hiding for a hiding (#5322)
Cause: on mote (macOS 27.2) WebKit's own document.hidden stayed true from
the page's load to the end of the run, the panel shown or not, and WebKit
fired no visibilitychange of its own (logged every 2ms in an instrumented
copy of the test). The test page dispatches visibilitychange from the
shown signal too, as app.js does; there it read hidden=true with the mark
just taken off, so it wrote marked=false play="running" as the hiding's
record and fetched /hidden. That stale /hidden sat in the host's channel,
so the panel's second round (Escape) showed the window again before its
hidden signal reached the page, and reported the stale record. The log of
a red run shows "got /hidden, show" in round 2 with no hidden signal
before it. The product is not at fault: the hidden signal reaches the
page on both of Wails' hides, and the page is paused while hidden.

Fix: the test page counts a visibilitychange as a hiding only outside the
shown signal's own dispatch.

Ran (mote, macOS 27.2, through mote-run):
- old test, -run TestPanelHiddenByWailsMarksPageOutOfSight -count=20:
  3 of 20 red with the issue's exact message.
- fixed, both visibility tests -count=20: ok, twice (the second at this
  commit's tree).
- go test ./internal/gui -count=1: ok (117.7s).
- gofmt -l internal/gui: clean.

Broken by hand, with the fix:
- WindowLostFocus no longer ExecJS's the hidden signal: 3 of 3 red
  ("timed out waiting for the page to see itself hidden").
- Escape's binding a plain w.Hide(): 3 of 3 red, the same.

Not tried: the full go test ./... — mote's suite lock had six suites
queued ahead; it is queued, and its result goes on #5322. Not tried on a
Mac with the panel really on screen (CI's runner and mote only).

Fixes #5322
2026-11-08 14:13:34 +08:00
yetone e0ee9265ef gui: TestClosingWindowMarksPageOutOfSight reads hidden as app.js does and waits for the page (#4924)
The test page read document.hidden from WebKit, which app.js never does:
app.js makes hidden and visibilityState follow magpie's signal (#4293).
WebKit turns an ordered-out window's document.hidden on in its own time
and fires no visibilitychange of its own, so the page recorded the hiding
only if WebKit's value was already true when magpie's signal (an async
ExecJS after orderOut) arrived. When it wasn't, nothing was recorded, the
window was shown again after a fixed 500ms, and the host waited 8s for a
report that could never come: "timed out waiting for the page's hidden
report", as on macOS CI at 4a9cfb52e and in a full run on mote.

A probe on mote showed WebKit reporting hidden=true for this page from the
start, before the window was ever ordered out, so there the old test
passed on WebKit's value, not on magpie's signal.

The page now overrides hidden and visibilityState the way app.js does,
and says when it has seen itself hidden; the window is shown again only
after that (a wait on state, 15s bound), not after a fixed pause. The
runAppKit bound is 2 minutes to cover its waits. app.js is unchanged.

Run on mote (macOS) at this tree:
- Injected WebKit reporting visible when the signal arrives (hidden and
  visibilityState pinned to visible in the page): old test red on both
  tests with "timed out waiting for the page's hidden report"; new test
  green.
- hideWebview's signal broken by hand (pageHiddenJSOn returns ""): new
  test red on both, "timed out waiting for the page to see itself hidden".
- No injection: green, -count=3.
- go vet ./internal/gui: ok; gofmt -l: clean.
- go test -count=1 ./internal/gui: only TestMainWindowCorners red, the
  separate #3949, which #4924's body names as well.
Not tried: a 1.5s busy page or a 300ms-late orderOut as the injection;
neither turned the old test red on mote, since WebKit says hidden there
throughout. A CI macOS runner itself.
2026-11-05 01:37:29 +08:00
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
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