From 1d5b5dc2da76d94a5ec7d41794307919a004595f Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 8 Nov 2026 13:10:00 +0800 Subject: [PATCH] gui: the panel's visibility test takes only a hiding for a hiding (#5322) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- internal/gui/window_visibility_darwin_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/gui/window_visibility_darwin_test.go b/internal/gui/window_visibility_darwin_test.go index fb7cc14d6..e5105534c 100644 --- a/internal/gui/window_visibility_darwin_test.go +++ b/internal/gui/window_visibility_darwin_test.go @@ -28,6 +28,14 @@ import ( // recorded nothing, and the window was shown again after a fixed pause with // nothing to report (#4924). The window is now shown again only once the // page has said it saw itself hidden. +// +// On mote (macOS 27.2) WebKit's own document.hidden stayed true from load +// to the end, the window shown or not, with no visibilitychange of its own. +// The shown signal's own visibilitychange then read hidden and unmarked, +// and was taken for the next hiding: its record and its /hidden reached +// the host before the panel's Escape was told, and the panel's second +// round failed with marked=false play="running" (#5322). Only a +// visibilitychange outside the shown signal counts as a hiding now. func TestClosingWindowMarksPageOutOfSight(t *testing.T) { out, err := runAppKit(t, 2*time.Minute, []string{"MAGPIE_TEST_WINDOW_VISIBILITY=1"}) if err != nil || !strings.Contains(string(out), "window visibility: ok") { @@ -73,7 +81,7 @@ for (const [k, off] of [["hidden", true], ["visibilityState", "hidden"]]) { const own = Object.getOwnPropertyDescriptor(Document.prototype, k)?.get; own && Object.defineProperty(Document.prototype, k, { configurable: true, get() { return outOfSight ? off : own.call(this); } }); } -let hiddenTold = false; +let hiddenTold = false, showing = false; window.magpieWindowVisibility = (visible) => { if (visible) hiddenTold = false; // shown again: what it last saw while hidden, once @@ -84,10 +92,14 @@ window.magpieWindowVisibility = (visible) => { } outOfSight = !visible; document.documentElement.classList.toggle("magpie-out-of-sight", !visible); + showing = visible; document.dispatchEvent(new Event("visibilitychange")); + showing = false; }; +// a hiding is what follows a hide: the shown signal's own event is not one, +// though WebKit may still say hidden then document.addEventListener("visibilitychange", () => { - if (document.hidden) { + if (document.hidden && !showing) { localStorage.setItem("hiddenProbe", JSON.stringify({ hidden: document.hidden, state: document.visibilityState,