gui (Windows): a re-entrant openMain during WebView2 Embed leaves an orphan main window that cannot be closed
What happens
On Windows (lightweight/tray mode), a double-click on the tray icon or a repeated tray click while the main window is being created can leave magpie with two main windows: one it thinks it holds and one it does not. The leftover window cannot be closed — clicking its X hides the other one — and after that magpie draws nothing in its place.
Why
Window.NewWithOptions on Windows goes through WebView2's chromium.Embed, which pumps Win32 messages on the UI thread before it returns. openMain sets h.main only after makeMain returns, so everything the nested pump dispatches in between re-enters openMain while h.main is still nil, and each re-entry creates another window and overwrites h.main. makeMain's WindowClosing hook then compares against h.gone alone and cancels every close but that one, hiding h.main instead: an orphaned window's X hides the live one.
The same shape applies to panelWin (a tray click during panel creation makes a second panel) and to OpenRemote (a second link opened while the first window is being embedded).
Fix branch
https://github.com/qq01-hub/magpie/tree/fix/windows-reentrant-window-make (25543231c)
Compare: https://github.com/yetone/magpie/compare/main...qq01-hub:magpie:fix/windows-reentrant-window-make
pendingMain/pendingRemotemerge a re-entrant call into the creation already in flight (latest non-empty URL, reveal flags upgraded toward visible), andmakingPanelcoalesces panel creation. Each is reset on the way out, including an early return.makeMain'sWindowClosinghook now asks whether the window is stillh.main(mainClosingHides, checked on the main thread) and lets any superseded or orphaned window close for good instead of cancelling and hiding the live one.openMainnavigates the new window to a URL a re-entrant call asked for, andOpenRemotelikewise retitles/navigates.
Verification (Windows 11 amd64, Go 1.26.8, based on 918467f6c)
go test -count=1 -run 'TestMainClosingHides|TestPendingMain|TestPendingRemote|TestPanel' ./internal/gui— 12 passed.go vet -tags nogui ./internal/gui,gofmt -l,git diff --checkclean.- Not run: a real double-click race on a Windows desktop with WebView2 (the nested pump can't be reproduced in a test), the wider
internal/guisuite.
@yetone 佬,这个 Windows 重入窗口的修复我这边修完推在 qq01-hub/magpie 上了(fix/windows-reentrant-window-make,25543231c),改动说明和跑过的测试都在上面,有空帮忙瞅一眼哈。
Fixed in v0.1.4964 (71f49757c), ported from Q呀's (@qq01-hub) fix branch, thanks. On Windows, a double click or a second tray click while magpie is still opening its main window (or the panel, or a remote window) no longer opens a second one. The second click goes into the window already on its way. If an extra main window is ever left behind, it now closes when you close it.
Not tried on a real Windows machine for this port: the tests that cover it are portable and ran on macOS, and our Windows box couldn't be reached. Leaving this open for the reporter to confirm.
这条看起来已经修了 —— 确认一下就可以关(2026-11-29,上游 85cdca969 之后)。
提交 71f49757c「gui: a window being made on Windows is not made twice, and an orphan main window closes」
Windows 上正在创建的窗口不再被创建两次,孤儿主窗口也会关掉 —— 与这条的 re-entrant openMain during WebView2 Embed 对应。
确认了就关即可;若还有不顺手的地方,写一句现象我继续看。