Skip to content

Commit 0ed793f

Browse files
authored
Fix recurring stuck/unfocusable main window in menu-bar-only mode (#223)
In menu-bar-only mode the app runs as .accessory, where a visible main window can't become key/active — it shows but can't take focus, so the whole UI appears frozen (can't navigate or change settings). SwiftUI's WindowGroup still instantiates the window at launch, and configureWindow forced it front via orderFrontRegardless(), racing MenuBarManager's hideMainWindow(). When that race lost, the window stayed visible but dead. configureWindow now keeps the window hidden when the app is .accessory; it's shown with .regular policy when opened from the menu bar (the intended menu-bar-only flow), so a visible window is always focusable. Co-authored-by: thefourCraft <thefourCraft@users.noreply.github.com>
1 parent 9068f96 commit 0ed793f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

native-macos/Zerm/WindowManager.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ class WindowManager: NSObject {
4343
window.setFrameAutosaveName(Self.mainWindowAutosaveName)
4444
applyInitialPlacementIfNeeded(to: window)
4545
registerMainWindowIfNeeded(window)
46-
window.orderFrontRegardless()
46+
47+
// Guard the recurring "stuck window" bug. In menu-bar-only mode the app runs as
48+
// .accessory, where a visible main window cannot become key/active — it shows but
49+
// can't take focus, so the whole UI looks frozen (can't navigate or change settings).
50+
// SwiftUI's WindowGroup still instantiates the window at launch, and forcing it front
51+
// here races MenuBarManager's hideMainWindow(). If we're .accessory, keep the window
52+
// hidden; it is shown with .regular policy when opened from the menu bar.
53+
if NSApplication.shared.activationPolicy() == .accessory {
54+
logger.notice("configureWindow: app is .accessory (menu-bar-only) — keeping main window hidden to avoid an unfocusable window")
55+
window.orderOut(nil)
56+
} else {
57+
window.orderFrontRegardless()
58+
}
4759

4860
// SwiftUI restores ITS OWN autosave frame (keyed by the full view-hierarchy
4961
// type string) AFTER this method returns, potentially overriding our placement.

0 commit comments

Comments
 (0)