Skip to content

Commit 04bdc17

Browse files
committed
Fix floating bar queries from foregrounding main app
1 parent 1974e13 commit 04bdc17

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

desktop/Desktop/Sources/FloatingControlBar/FloatingControlBarWindow.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,14 @@ class FloatingControlBarManager {
848848
}
849849

850850
/// Toggle visibility.
851+
/// When visible with an AI conversation open, collapse to the pill instead of hiding.
851852
func toggle() {
852853
guard let window = window else { return }
853854
if window.isVisible {
854-
AnalyticsManager.shared.floatingBarToggled(visible: false, source: "shortcut")
855-
hide()
855+
if window.state.showingAIConversation {
856+
window.closeAIConversation()
857+
}
858+
// Already collapsed pill — do nothing (don't hide)
856859
} else {
857860
AnalyticsManager.shared.floatingBarToggled(visible: true, source: "shortcut")
858861
show()
@@ -980,14 +983,20 @@ class FloatingControlBarManager {
980983
// MARK: - AI Query
981984

982985
private func sendAIQuery(_ message: String, barWindow: FloatingControlBarWindow, provider: ChatProvider) async {
983-
// Hide the bar, capture a clean screenshot, then restore — same path for both typed and PTT
984-
barWindow.orderOut(nil)
986+
// Hide the bar visually (without ordering it out) so we keep key-window ownership
987+
// and avoid promoting the main Omi window while capturing a clean screenshot.
988+
let previousAlpha = barWindow.alphaValue
989+
let previousIgnoresMouseEvents = barWindow.ignoresMouseEvents
990+
barWindow.alphaValue = 0
991+
barWindow.ignoresMouseEvents = true
985992
try? await Task.sleep(nanoseconds: 150_000_000) // 150ms for window to disappear
986993
let screenshotData = await Task.detached { () -> Data? in
987994
guard let url = ScreenCaptureManager.captureScreen() else { return nil }
988995
return try? Data(contentsOf: url)
989996
}.value
990-
barWindow.makeKeyAndOrderFront(nil)
997+
barWindow.alphaValue = previousAlpha
998+
barWindow.ignoresMouseEvents = previousIgnoresMouseEvents
999+
barWindow.orderFrontRegardless()
9911000

9921001
AnalyticsManager.shared.floatingBarQuerySent(messageLength: message.count, hasScreenshot: screenshotData != nil)
9931002

desktop/Desktop/Sources/Providers/ChatProvider.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,11 +1962,15 @@ A screenshot may be attached — use it silently only if relevant. Never mention
19621962
log("ChatProvider: Browser tool \(name) called without extension token — aborting query and prompting setup")
19631963
self?.needsBrowserExtensionSetup = true
19641964
self?.stopAgent()
1965-
// Bring the app to the foreground so the setup sheet is visible
1966-
// (the failed browser attempt may have opened Chrome, stealing focus)
1967-
NSApp.activate(ignoringOtherApps: true)
1968-
for window in NSApp.windows where window.title.hasPrefix("Omi") {
1969-
window.makeKeyAndOrderFront(nil)
1965+
// Keep floating-bar sessions non-intrusive: do not foreground
1966+
// the main window when the query originated from the floating bar.
1967+
if sessionKey != "floating" {
1968+
// Bring the app to the foreground so the setup sheet is visible
1969+
// (the failed browser attempt may have opened Chrome, stealing focus)
1970+
NSApp.activate(ignoringOtherApps: true)
1971+
for window in NSApp.windows where window.title.hasPrefix("Omi") {
1972+
window.makeKeyAndOrderFront(nil)
1973+
}
19701974
}
19711975
}
19721976
// Show the floating bar so the user has an always-on-top UI

0 commit comments

Comments
 (0)