Commit Graph
7 Commits
Author SHA1 Message Date
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
yetone 9e63476087 gui: on Windows only the window's frame resizes it, not the page's edges (shangyuan0818)
shangyuan0818 on Discord: the top of the page, just under Windows' title
bar, resized the window's height as the frame does. Cause: Wails' page
runtime (drag.ts, v3.0.0-beta.24) arms an edge resize SM_CYSIZEFRAME px
inside the page on every edge whenever the window is resizable on
Windows, framed or not (on Linux only when frameless, never on the Mac),
and posts wails:resize:<edge>, which Go turns into WM_NCLBUTTONDOWN
HTTOP/HTLEFT/... The main window is framed on Windows, so its top, left,
right and bottom page edges all resized it. On the main window, on
Windows only, magpie now turns that switch off once Wails' runtime is
ready (WindowRuntimeReady), wrapped so Wails' own setResizable(true)
right after, or on a reload, keeps it off. The native frame and window
resizability are untouched.

Run:
- Windows 11 box (xiaomi-gpu), sandbox HOME, GOOS=windows builds of
  origin/main dc1cfe015 and of this change, the real WebView2 page driven
  over CDP (mouse move, press, move, release via Input.dispatchMouseEvent,
  chrome.webview.postMessage recorded):
  - main: top (y=1) cursor ns-resize, posts wails:resize:n-resize; left
    posts w-resize; bottom posts s-resize.
  - this change: no resize cursor and no resize message on any of the
    three; the top drags the window as the rest of the header does
    (wails:drag). Hook present after a page reload.
  - native frame on this change, WM_NCHITTEST: frame top 12 (HTTOP),
    left 10, right 11, bottom 15, title bar 2 (HTCAPTION), page top 1
    (HTCLIENT); WM_NCLBUTTONDBLCLK on the caption maximises, restore
    restores.
- TestFrameOnlyResizeStaysOff (node, both orders, hook twice, no runtime).
  Broken by hand (wrapper removed, setResizable(false) only): red on
  "hook before Wails" and "hook twice".
- mote: go test ./internal/gui/ (gui tags), GOOS=windows go vet
  ./internal/gui/, GOOS=linux CGO_ENABLED=0 go vet -tags nogui, gofmt -l.
  Full suite -tags nogui -timeout 45m at dc1cfe015 + this change (which
  is !nogui only, so not compiled there): red TestWSLColdPlaceOpensNothing
  (#3924), TestPluginStreamsPastTheBudgetWait (#3946), internal/provider
  TestUnreadLoginsWriteErrorsKeepCredentials (#3632),
  TestTUIFetchesSubscriptionModels (#3919); all four red on dc1cfe015
  alone. internal/gui: TestMainWindowCorners/macOS_26_SDK red on macOS 27,
  same on dc1cfe015 alone, filed #3949.

macOS and Linux: the hook is registered only when GOOS is windows, and
drag.ts never arms on a framed window there.

Not tried: real mouse drags on the Windows box. A Windows Security dialog
was up over the whole screen, so synthetic clicks went to its dim layer
and the window did not move; the frame was checked by hit test instead.
2026-10-28 05:50:26 +08:00
yetone d3191a51c8 gui: with Hide accounts on, an account's eye shows that one account in this window (yogurt36)
yogurt36 on Discord, for a screen share: with Hide accounts on, one
account should be readable while the others stay masked. Now an
account's name on the provider editor's row (accountNameButton and the
one-account line) and on its Usage card (quotaWho) has a quiet eye, in
sight on hover or keyboard focus, with an aria-label. A click shows
that account, its address and the name the user gave it together
(kin), everywhere the window draws it, tooltips included: the shown
set is skipped in hits(), which every mask goes through. It lives in
memory only. The tray panel keeps hiding it, and closing the window
hides it again: the page stays loaded while the window is hidden, so
hideMain runs mainClosedJS (hideAccounts.closed) first. With Hide
accounts off there is no eye. Strings in zh, zh-TW, ja and de.

Run (macOS, playwright 1.62.0, rebased on 630fd1d69; at push 0f6615ffc, site only, came under it):
- account-eye.test.cjs: 20/20 in chromium and webkit, en zh zh-TW ja
  de, 900px and 360px (no select, no stripe, no sideways scroll, a
  click scrolls nothing, Tab (Alt+Tab in WebKit) reaches the eye).
- Red on the old code (feature stashed): both tests fail.
- Broken by hand, each red, then restored: the shown check in hits();
  closed() without shown.clear(); kin() returning only the address.
- TestClosingHidesShownAccounts (new): red without shown.clear() and
  without the ExecJS(mainClosedJS) call in hideMain.
- go test -run 'TestCoreScriptBudget|TestBuiltinClientsLoaded|
  TestClosingHidesShownAccounts' ./internal/gui: ok. app.js
  1,306,355 bytes, under 1,321,319; budgets not raised.
- i18n-keys.test.cjs: 4/4.
- gofmt -l clean; go vet (mac), GOOS=linux go vet -tags nogui,
  GOOS=windows go vet ./internal/gui; go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.

After the last rebase one chromium en/zh run of account-eye showed 1
fail of 4 with 179MiB free on the disk; its log wasn't kept, so the
test is unnamed. Every run since, with its log kept, passed: 4/4 and
then 20/20 in both engines.

Not run: the whole GUI suite and the full go test ./internal/gui
(another session's suite held the machine and the disk was full; one
link hit ENOSPC and passed on retry). They run after the push.
Not tried: the real Wails window's close (hideMain) by hand.
2026-10-26 18:18:24 +08:00
forever 2c31129692 gui: on macOS 26 the main window has a plain title bar's corners (TextEdit's, not Finder's), its traffic lights still in the header (waitingsnow) (#1042)
* gui: on macOS 26 the main window has a plain title bar's corners (TextEdit's, not Finder's), its traffic lights still in the header (waitingsnow)

From macOS 26 a window with a toolbar has larger corners than one with a
plain title bar: 26pt, Finder's, against 16pt for TextEdit or an
Electron app. The main window has an empty toolbar only to inset its
traffic lights into the page's header (Wails' MacTitleBarHiddenInset),
so its corners were a toolbar window's. On macOS 15 a toolbar doesn't
change them (12pt either way, measured on 15.8).

On macOS 26 and later plainTitlebar now takes the toolbar off
(insetLights, titlebar_darwin.go), and MagpieLights keeps the lights and
the title bar's 66pt height where the toolbar had them. AppKit lays the
title bar out again at its own 32pt after a resize or zoom, a new title,
a new appearance and leaving full screen; the lights are put back once
it is done, and AppKit's hover tracking is told where they went. Their
autoresizing mask keeps their distance from the top: AppKit draws a new
system appearance (light or dark, more contrast, less transparency)
before the run loop turns, which drew them 8pt above the window for one
frame. A sheet, such as the folder chooser, still begins below the title
bar (Wails' window delegate gets window:willPositionSheet:usingRect:,
which places this window's sheets only).

A first press while another app is in front still moves the window from
anywhere in the 66pt title bar, as AppKit moved it with the toolbar
(firstPress, a local mouse-down monitor). AppKit's own band is now a
plain title bar's 32pt; below it the page doesn't take a first press, so
the press would only have brought the window forward. A press on a view
that takes a first press (a traffic light, a resize edge) is left alone,
as AppKit leaves it.

The macOS version is asked at run time. go build and go test build the
cgo objects for the Mac's own macOS, where @available(macOS 26.0, *) is
compiled away: a test binary built so on 26.7.1 took the toolbar off on
15.8. An older macOS, the lights on the right (a right-to-left language)
or a title bar not laid out as expected keep the toolbar. Linux and
Windows are unchanged; the GTK 3 comment now says its corners stay
square.

TestMainWindowCorners (new; darwin, run by CI's macOS job) measures the
main window beside a plain and a toolbar window in a process of its own
(runAppKit, so WebKit's data stays out of the real ~/Library): once
shown, after a new title and size and a new system appearance, as AppKit
draws that appearance, a first press 20, 40, 60 and 70pt below the top
while no window is key, and where a sheet begins.
TestMainWindowRightToLeft launches it right to left. Both pass on macOS
26.7.1 (3 runs in a row), 26.6.2 (CI's) and 15.8 Intel, where the
toolbar stays. With each part taken out, they fail:
- the change itself: "corners of 26.00pt; a window with a plain title
  bar has 16.00pt, one with a toolbar 26.00pt";
- putting the lights back: "traffic light 1 at [16 16] (x, y from the
  top left), the toolbar had it at [26 26]";
- the height: "a title bar 32pt tall, the toolbar's was 66pt";
- the mask: "as AppKit draws a new system appearance, traffic light 1
  is at [26 -8]";
- the sheet's place: "a sheet on a short window begins 16pt below its
  top; below the toolbar it began 66pt";
- the press monitor: "a first press 40pt below the top, with another
  app in front, began 0 window drags; with the toolbar it began 1";
- the right-to-left check: "the traffic lights are on the right, and
  the main window's toolbar was taken off";
- the run-time check (@available instead), on 15.8: "a toolbar doesn't
  change the corners on this macOS, yet the main window's was taken
  off".
The presses are sent within the test's own process, and a drag is
counted, not begun; no system setting changes.

The real app on 26.7.1, built from this commit and driven through
Accessibility under a HOME of its own, has 16.25pt corners (26.50pt on
main) and its lights where main has them, through resize, zoom, light
and dark, a new title, full screen, minimise, close and show, a
maximised start, and the window lightweight mode makes again. A real
pointer and a key window's press were not tried. go vet, the three
builds and go test -tags nogui ./... pass.

* gui: where AppKit gives magpie the Mac's earlier design (an SDK before macOS 26's, or UIDesignRequiresCompatibility), the main window keeps its toolbar (waitingsnow)

The main window's toolbar comes off only in the design of macOS 26,
where a toolbar gives a window larger corners. AppKit gives a program
that design from macOS 26 when the program is linked against the macOS
26 SDK or a later one and its Info.plist doesn't set
UIDesignRequiresCompatibility; the last commit asked only for the macOS
version. A program linked against an earlier SDK gets the earlier design
on macOS 26 too: yetone's test binary (Go 1.26.3, Xcode 26.2) names SDK
11.0, and on 26.2 every window there had 12pt corners, yet the main
window's toolbar was taken off and TestMainWindowCorners failed at every
stage.

designOf26 now reads each at run time: the macOS version (NSProcessInfo),
the key (NSBundle) and the SDK the program names. The SDK is in
LC_BUILD_VERSION, or in LC_VERSION_MIN_MACOSX in a program that runs on
macOS 10.13, as go build links one for an Intel Mac. The header is read
through _NSGetMachExecuteHeader (crt_externs.h):
dyld_get_program_sdk_version is declared only in dyld's private header,
and it doesn't see the key (27.0 in a bundle that sets it, where AppKit
gives the earlier design). The comment no longer says go build builds
for the Mac's own macOS: the program names 11.0, and it is clang that
compiles the cgo code for the Mac's own macOS (ld: "built for newer
'macOS' version (26.0) than being linked (11.0)"), where
@available(macOS 26.0, *) would be compiled away.

TestMainWindowCorners now runs the windows' program twice, as linked
against the macOS 26 SDK and against macOS 15's (runAppKitSDK; stampSDK
rewrites the SDK in a copy and signs it again), so on macOS 26 it checks
both designs whatever SDK the toolchain names. In the earlier design it
checks that the main window keeps its toolbar. gui-shell.md says which
design gets the change, which SDKs the test runs with, why the key has
no test, and how to run it as for an Intel Mac.

Both subtests and TestMainWindowRightToLeft pass on 26.7.1 (arm64, 3
runs in a row, and amd64 under Rosetta), 26.6.2 (arm64, as CI) and 15.8
(Intel). With each new part taken out, its subtest fails:
- reading the SDK (designOf26 answering yes after the macOS and the
  key): "a toolbar doesn't change the corners in this design, yet the
  main window's was taken off", with macOS 15's SDK;
- 26.0 itself (> for >=): "corners of 26.00pt; a window with a plain
  title bar has 16.00pt, one with a toolbar 26.00pt", with the macOS 26
  SDK;
- reading LC_VERSION_MIN_MACOSX, or 26.0 there, built for amd64: the
  corners message, with the macOS 26 SDK;
- the macOS version, asked with @available instead, built on 26.7.1 for
  amd64 and run on 15.8: the toolbar message, with the macOS 26 SDK.
Taking out the last commit's parts fails the macOS 26 SDK subtest or
TestMainWindowRightToLeft as before.

UIDesignRequiresCompatibility is checked by hand, not in a test: AppKit
reads it from an app bundle's Info.plist, LaunchServices registers each
bundle that runs (and keeps a temporary one after it is deleted), and in
a process run from a bundle a press sent within it began a window drag
in only 3 of 12 runs. On 26.7.1 the test program in a bundle whose
Info.plist sets the key has 12pt corners like every window there, and
keeps its toolbar; in a bundle without the key it has 16pt and no
toolbar, as when run on its own. With the key's check taken out, the
toolbar is taken off although AppKit gives the earlier design. The
bundles were unregistered (lsregister -u) and deleted.

go vet, the three builds, go test -tags nogui ./... and go test
./internal/gui/... pass. The real app wasn't run again.

* ci: run the checks again (waitingsnow)

test (macos-latest) failed in TestRelayKeepsClientAlive (internal/gateway, 1 ping in a 150ms gap), a timing test this PR doesn't touch; it passes on main and 5 times of 5 locally.
2026-10-13 09:55:23 +08:00
yetone 31b903fed2 gui: a Dock click goes to the main window on its own Space, not pulls it to the current one (#1252)
The window has MoveToActiveSpace so that a first show, or an Open from
the menu bar, puts it on the Space the user is on (a window first shown
while another app was full screen belonged to that Space from then on).
The Dock's reopen also went through openMain's Show and Focus, so with
the window open on another Space a Dock click pulled it over instead of
switching to it, as other Mac apps do.

The window now carries MoveToActiveSpace only while it is shown
(showHere: set, Show, Focus, cleared 500ms later, since clearing it at
once loses the move). The Dock's reopen (reopenMain) activates the app
and leaves an open window where it is, so macOS switches to its Space; a
closed, hidden or minimised window, or one still loading, is shown on the
current Space as before. The menu bar panel and its Open are unchanged.

TestDockReopenKeepsTheWindowsSpace (darwin, cgo) runs a real Wails app:
open, reopen while open (the flag is never set, the window stays open),
hidden then reopened, and minimised then reopened. With the old reopen
it fails ("the shown window stays on its Space").

Tried for real on this Mac (macOS 26.2), on sandbox .app builds of the
old and new code under a sandbox HOME, with a second Space added and
removed afterwards. Old build: window open on Space 1, Dock reopen from
Space 2 left the user on Space 2 and moved the window there. New build:
the same reopen switched to Space 1 and the window stayed there. A
minimised or closed window was shown on Space 2, the current one. The
menu bar panel opened and closed on both Spaces. go test -tags nogui
./internal/gui/... and go test ./internal/gui (cgo) pass under a temp
HOME; go vet, and GOOS=linux / GOOS=windows go vet -tags nogui pass.
Not tried on a full-screen Space or with several displays.
2026-10-08 16:38:14 +08:00
yetone 4a2f538c61 gui: lightweight mode, off by default, lets a closed panel's or window's webview go and makes it again when it is opened (somls on #580: GUI版可否增加轻量模式,关闭面板退出webview,减少资源占用) — closing the tray panel or the main window only hid it, so each kept its page and, on a Mac, its WebKit WebContent process (about 65 MB each at start, 95–100 MB after use) for as long as magpie ran. Settings → General now has Lightweight mode (轻量模式), shown in the app only (not on a browser's page) and kept as this computer's own through a sync or a restored backup (KeepOwn): with it on, a window found closed on two looks in a row 30 s apart (lightStep) is let go 30–60 s after it was closed, so a panel opened again soon after is still the same one at once. Letting go happens on the main thread under a new h.winMu: the window field is set to nil, the panel is unhooked from the tray icon (AttachWindow(nil); left click goes through magpie's own OnClick), and the main window is marked gone so its closing hook, which otherwise cancels a close and hides, lets it close; on the Mac the WKWebView is taken out of the window first (stopLoading, delegates and script handlers cleared, removed from its superview), since Wails' NSWindow close alone left the WebContent process alive for minutes. Opening it again (the tray icon, ShowMain, an import link, the Dock) makes the window anew with the options it was started with (makeMain/makePanel, moved out of Run with their hooks), its text size and title bar or Hyprland name (madeAgain), on Windows shown only once its page has loaded; every other path that reached h.main or h.panel (fit, tint, zoom, hide, glide, the Windows title-bar tint, the Hyprland click watch, the folder picker) now goes through the main thread and does nothing to a window let go; Linux keeps running with no window left (DisableQuitOnLastWindowClosed). Measured in a sandbox build under a temp HOME on other ports: started in the tray with the setting on, two WebContent processes of ~65 MB each; about a minute later both windows were let go and both processes ended (GPU and Networking, ~56 MB, are shared and stay; magpie's own process is unchanged), so the saving is ~130 MB idle and up to ~200 MB after use; the main window and the panel were then opened again with their pages, tinted and at the tray icon, closed, let go a second time, and magpie quit cleanly, with fit/tint/zoom calls every 0.2 s through a release crashing nothing. Windows and Linux build but were not run. TestLightStep and TestLightweightKeptAndOwn are new; lightweight.test.cjs (WebKit, en and zh: the row, off by default, On/Off posted as lightweight true/false, another setting's save keeping it, no scroll, no left-border accent, no row on a browser's page) is new and passes, as do click-scroll, settings-sections and searcher-pick. go vet ./internal/..., go build (darwin GUI), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-03 00:24:49 +08:00
yetone 597c347ba8 gui: the Mac window opens on the Space you are on, and closing it in full screen leaves no black Space (StringKe on Discord) — magpie keeps no window position, so what stuck was macOS's own: the window, made with only full-screen-primary, belonged to the Space it was last shown on and Open took the user there; restarted to update while another app was full screen, it joined that app's Space for good. It now also moves to the active Space whenever shown (130, can still go full screen: checked in AppKit, enter and exit both report). Closing a full-screen window hid it where it was, leaving its full-screen Space empty and black; it now leaves full screen first and hides on WindowDidExitFullScreen (3s fallback), and an Open meanwhile keeps it. TestMainWindowFollowsActiveSpace and TestCloseStepLeavesFullscreen fail without the change. go vet, go build (darwin GUI), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-09-30 18:41:10 +08:00