diff --git a/apps/macos/Sources/Clawdis/MenuBar.swift b/apps/macos/Sources/Clawdis/MenuBar.swift index 445462458..e513ae5ec 100644 --- a/apps/macos/Sources/Clawdis/MenuBar.swift +++ b/apps/macos/Sources/Clawdis/MenuBar.swift @@ -15,6 +15,11 @@ struct ClawdisApp: App { @State private var statusItem: NSStatusItem? @State private var isMenuPresented = false @State private var isPanelVisible = false + + @MainActor + private func updateStatusHighlight() { + self.statusItem?.button?.highlight(self.isPanelVisible) + } init() { _state = StateObject(wrappedValue: AppStateStore.shared) @@ -49,6 +54,9 @@ struct ClawdisApp: App { } .defaultSize(width: SettingsTab.windowWidth, height: SettingsTab.windowHeight) .windowResizability(.contentSize) + .onChange(of: self.isMenuPresented) { _, _ in + self.updateStatusHighlight() + } } private func applyStatusItemAppearance(paused: Bool) { @@ -62,7 +70,7 @@ struct ClawdisApp: App { WebChatManager.shared.onPanelVisibilityChanged = { [self] visible in self.isPanelVisible = visible - self.statusItem?.button?.highlight(visible) + self.updateStatusHighlight() } let handler = StatusItemMouseHandlerView() @@ -70,8 +78,8 @@ struct ClawdisApp: App { handler.onLeftClick = { [self] in self.toggleWebChatPanel() } handler.onRightClick = { [self] in WebChatManager.shared.closePanel() - self.statusItem?.button?.highlight(false) self.isMenuPresented = true + self.updateStatusHighlight() } button.addSubview(handler) diff --git a/apps/macos/Sources/Clawdis/WebChatWindow.swift b/apps/macos/Sources/Clawdis/WebChatWindow.swift index b6118d6d5..b2592ba8a 100644 --- a/apps/macos/Sources/Clawdis/WebChatWindow.swift +++ b/apps/macos/Sources/Clawdis/WebChatWindow.swift @@ -353,14 +353,16 @@ final class WebChatWindowController: NSWindowController, WKNavigationDelegate, N private func installDismissMonitor() { guard self.localDismissMonitor == nil, let panel = self.window else { return } - self.localDismissMonitor = NSEvent.addLocalMonitorForEvents( + self.localDismissMonitor = NSEvent.addGlobalMonitorForEvents( matching: [.leftMouseDown, .rightMouseDown, .otherMouseDown] - ) { [weak self] event in - guard let self else { return event } - if event.window !== panel { - self.closePanel() + ) { [weak self] _ in + guard let self else { return } + let pt = NSEvent.mouseLocation // screen coordinates + if !panel.frame.contains(pt) { + Task { @MainActor in + self.closePanel() + } } - return event } }