gui: a restart to update leaves the Mac's menu bar icon for the next magpie (Mitsuha, audie)

From v0.1.1354 a restart to update hands the gateway over, and the old
magpie hides its own menu bar item with Wails' Hide, which is
[statusItem setVisible:NO]. AppKit keeps that in the app's defaults by
the item's autosave name ("NSStatusItem VisibleCC Item-0" = 0 on macOS
26), and the next item made under that name starts hidden. So after the
update the icon was gone, and quitting and reopening didn't bring it
back (Mitsuha on v0.1.1364; audie on two Macs, macOS 27.0.1).

Evidence: a 30-line Cocoa probe made a status item, setVisible:NO, and
every later launch of the same program started with visible=0 and the
key = 0; removeStatusItem kept nothing; removing the key brought it back
on the next launch. This machine's com.yetone.magpie.sbhandover.plist
(the handover commit's own sandbox run) holds
"NSStatusItem VisibleCC Item-0" => false.

Fix (internal/gui/trayshown_darwin.go, app.go):
- leaveMenuBar (was the onHandedOver closure) queues forgetTrayHidden
  on the main thread after Wails' hide block, so the hide is made on
  screen but not kept.
- bringTrayBack, once per computer (a flag in the Mac's defaults, never
  in a WebDAV backup), forgets a kept hide before the tray is made: that
  repairs everyone an older magpie already hit. A hide kept after that
  is the user's and is left alone.
- A magpie handed over to by an older one (which still hides for good)
  forgets the hide once that pid has quit and shows its item, unless a
  hide was already kept when it started.
docs/subsystems/gui-shell.md says so under the handover.

Run (worktree at origin/main ed91aa04e):
- TestHandoverLeavesTheMenuBarIconForTheNextMagpie (AppKit child with a
  real Wails tray, CFFIXED_USER_HOME sandbox): ok, -count=3.
- Broken by hand: leaveMenuBar without forgetTrayHiddenLater -> "handing
  over kept the menu bar icon hidden for the next magpie (1 kept)";
  bringTrayBack without forgetTrayHidden -> "the icon an older magpie hid
  wasn't brought back (still hidden true, 1 kept)".
- go test ./internal/gui/ -count=1: ok 86.7s; go test -tags nogui
  ./internal/gui/: ok 67.2s.
- gofmt -l: nothing. go vet ./internal/gui/ (darwin), GOOS=linux go vet
  -tags nogui, GOOS=windows go vet: ok. go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.
- No GUI asset changed, so no Playwright run.

Not tried: a real signed update from v0.1.1367 to this build on the
user's bundle id; whether Control Center hides the new version's running
item live when the old one writes the key (the probe's running item kept
visible=1; the on-screen window list needs screen recording rights). Not
run: the full go test ./... (one package touched; other sessions are
queued for the suite). audie's WebDAV sync carries no tray setting and
doesn't restart magpie; the icon going there is taken to be the same
update's restart, not confirmed with them.
This commit is contained in:
yetone
2026-10-24 15:20:37 +08:00
parent ed91aa04ef
commit ccbbcbffcb
5 changed files with 245 additions and 11 deletions
+12 -1
View File
@@ -505,7 +505,18 @@ then calls `beginHandover` instead of the relaunch-after-exit. The steps:
Two magpies never show at once. On a Mac the old one lets go of its
instance lock before it gives the socket (`releaseInstance`), so the new
one's `runningAlready` takes it, and once the ack comes the old one hides
its menu bar icon, panel and window and leaves the Dock (`onHandedOver`).
its menu bar icon, panel and window and leaves the Dock (`onHandedOver`,
`leaveMenuBar`). AppKit keeps a status item's `setVisible:NO` in the
app's defaults by its autosave name (`NSStatusItem VisibleCC Item-0` on
macOS 26), which the new one's item and every later one start from, so
the hide is forgotten once it is made (`forgetTrayHiddenLater`,
[`trayshown_darwin.go`](../../internal/gui/trayshown_darwin.go)). From
v0.1.1354 to v0.1.1367 it wasn't, and the icon stayed gone after the
update, through a quit and reopen too (Mitsuha, audie). `bringTrayBack`
forgets a kept hide once per computer before the tray is made, and a
magpie handed over to by an older one forgets it again once that one has
quit (`awaitExit`), unless a hide was kept when it started: one kept after
the bring-back is the user's (`TestHandoverLeavesTheMenuBarIconForTheNextMagpie`).
On Linux the D-Bus name Wails holds can't be let go, so the new one serves
the gateway at once but waits for the old pid to end (`awaitExit`, at most
`handedOffWait`, 16 minutes) before it makes its app and tray; the old one