gui: the Mac's tray panel is made the first time it is opened

magpie made the quick panel as it started, hidden, so its page kept a
WebContent process of its own (~65 MB) for as long as magpie ran, for a
user who never opens the panel too. On the Mac it is now made by
panelWin on first open, the path lightweight mode already takes when it
let the panel go (madeAgain names it and hangs it on the tray icon).
Linux and Windows still make it at start: the made-again path hasn't
been run in a real window there.

Measured on mote, real window app, real account sandbox HOME:
- started plainly, at 40s: w32 (main) WebContent 69 MB + 65 MB;
  this change 65 MB alone, the panel's process gone.
- started as `magpie panel` (OpenPanel): both show the panel on screen
  (layer 101, 439x268 at 0,36, CGWindowList), with 2 WebContent
  processes of 65-66 MB each; magpie itself 175 MB vs 192 MB.
- a second `magpie panel` on the Mac only hands over (runningAlready);
  it never opened the panel, before or after.

Run: go test -run 'Panel|Light|Tray' ./internal/gui (mica, ok, with
TestPanelOnFirstOpen), go vet ./internal/gui darwin and GOOS=windows.
Not run: Linux GUI vet (no gtk4 dev packages in the WSL distro; the
Linux path is unchanged), a real tray click (no ssh-driven click; it
calls the same togglePanel as OpenPanel and the panel hotkey).
This commit is contained in:
yetone
2026-11-12 22:28:44 +08:00
parent 9192b78323
commit 182803ea7d
3 changed files with 30 additions and 4 deletions
+14 -4
View File
@@ -515,7 +515,13 @@ func Run(version string, showMain bool, link string) error {
e.Cancel()
})
h.panel = h.makePanel()
// The Mac's panel is made the first time it is opened (panelWin): made
// here, its page and WebContent process (~67 MB) sat hidden for as long
// as magpie ran, for a user who never opens it too. Elsewhere it is made
// now, as the made-again path hasn't been run in a real window there.
if !panelOnFirstOpen(runtime.GOOS) {
h.panel = h.makePanel()
}
h.main = h.makeMain("/?" + theme)
onFonts = h.fontsChanged
@@ -635,7 +641,9 @@ func Run(version string, showMain bool, link string) error {
})
}
h.tray.SetMenu(menu)
h.tray.AttachWindow(h.panel).WindowOffset(6)
if h.panel != nil { // one made later hangs itself on the icon (makePanel)
h.tray.AttachWindow(h.panel).WindowOffset(6)
}
// before Wails removes the item as the app quits, which would forget
// where the user put the icon (trayshown_darwin.go; nothing elsewhere)
h.app.OnShutdown(func() { keepTrayPlace() })
@@ -714,8 +722,10 @@ func Run(version string, showMain bool, link string) error {
// makes a window of its own (toolbarRounder), which deadlocks the
// main thread while a hidden background launch (an update's
// relaunch) is still inside FBSWorkspaceScenesClient on macOS 26.
nameWindow(h.panel, panelTitle)
ownFrame(h.panel) // KDE: no title bar of KWin's on it (#1283)
if h.panel != nil { // one made later is named as it is (madeAgain)
nameWindow(h.panel, panelTitle)
ownFrame(h.panel) // KDE: no title bar of KWin's on it (#1283)
}
markReady()
})
}
+5
View File
@@ -28,3 +28,8 @@ func lightStep(on, shown bool, ticks int) (int, bool) {
ticks++
return ticks, ticks >= lightTicks
}
// panelOnFirstOpen says whether the tray panel is made the first time it is
// opened rather than as magpie starts: on the Mac, where a hidden panel's
// page kept a WebContent process of its own (~67 MB) for nothing.
func panelOnFirstOpen(goos string) bool { return goos == "darwin" }
+11
View File
@@ -28,3 +28,14 @@ func TestLightStep(t *testing.T) {
}
}
}
// The Mac's tray panel is made when it is first opened, not at start: a
// hidden one kept a WebContent process of ~67 MB for a user who never
// opened it. Elsewhere it is still made at start.
func TestPanelOnFirstOpen(t *testing.T) {
for goos, want := range map[string]bool{"darwin": true, "linux": false, "windows": false} {
if got := panelOnFirstOpen(goos); got != want {
t.Errorf("panelOnFirstOpen(%s) = %v, want %v", goos, got, want)
}
}
}