Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

MenuBar issues fixed ; added multikey global shortcut - 1 key or 2 keys

altic-deve8f64175f089
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index b7334533..1d8f052d 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -75,6 +75,9 @@ struct ContentView: View {
@State private var accessibilityEnabled = false
@State private var hotkeyShortcut: HotkeyShortcut = SettingsStore.shared.hotkeyShortcut
@State private var isRecordingShortcut = false
+ @State private var pendingModifierFlags: NSEvent.ModifierFlags = []
+ @State private var pendingModifierKeyCode: UInt16?
+ @State private var pendingModifierOnly = false
@FocusState private var isTranscriptionFocused: Bool
@State private var overlayVisible: Bool = false
@@ -162,6 +165,9 @@ struct ContentView: View {
// Ensure no restart UI shows if we already have trust
if accessibilityEnabled { showRestartPrompt = false }
+ // Initialize menu bar after app is ready (prevents window server crash)
+ menuBarManager.initializeMenuBar()
+
// Configure menu bar manager with ASR service
menuBarManager.configure(asrService: asr)
@@ -215,13 +221,13 @@ struct ContentView: View {
}
guard isRecordingShortcut else {
- // Check for escape key to cancel ASR recording
if event.keyCode == 53 && asr.isRunning {
DebugLogger.shared.debug("NSEvent monitor: Escape pressed, cancelling ASR recording", source: "ContentView")
asr.stopWithoutTranscription()
return nil
}
DebugLogger.shared.debug("NSEvent monitor: Not recording shortcut, forwarding event", source: "ContentView")
+ resetPendingShortcutState()
return event
}
@@ -229,14 +235,18 @@ struct ContentView: View {
if keyCode == 53 {
DebugLogger.shared.debug("NSEvent monitor: Escape pressed, cancelling shortcut recording", source: "ContentView")
isRecordingShortcut = false
+ resetPendingShortcutState()
return nil
}
- let newShortcut = HotkeyShortcut(keyCode: keyCode, modifierFlags: eventModifiers)
+
+ let combinedModifiers = pendingModifierFlags.union(eventModifiers)
+ let newShortcut = HotkeyShortcut(keyCode: keyCode, modifierFlags: combinedModifiers)
DebugLogger.shared.debug("NSEvent monitor: Recording new shortcut: \(newShortcut.displayString)", source: "ContentView")
hotkeyShortcut = newShortcut
SettingsStore.shared.hotkeyShortcut = newShortcut
hotkeyManager?.updateShortcut(newShortcut)
isRecordingShortcut = false
+ resetPendingShortcutState()
DebugLogger.shared.debug("NSEvent monitor: Finished recording shortcut, isRecordingShortcut set to false", source: "ContentView")
return nil
} else if event.type == .flagsChanged {
@@ -250,33 +260,45 @@ struct ContentView: View {
guard isRecordingShortcut else {
DebugLogger.shared.debug("NSEvent monitor: Not recording shortcut (modifier), forwarding event", source: "ContentView")
+ resetPendingShortcutState()
return event
}
- let keyCode = event.keyCode
- let isModifierKeyPressed = eventModifiers.isEmpty == false
- if isModifierKeyPressed {
- // Map the actual key codes for modifier keys
- var actualKeyCode = keyCode
- if eventModifiers.contains(.command) {
- // Determine if it's left or right command based on key code
- actualKeyCode = (keyCode == 55) ? 55 : 54 // 55 = left cmd, 54 = right cmd
- } else if eventModifiers.contains(.option) {
- actualKeyCode = (keyCode == 58) ? 58 : 61 // 58 = left opt, 61 = right opt
- } else if eventModifiers.contains(.control) {
- actualKeyCode = (keyCode == 59) ? 59 : 62 // 59 = left ctrl, 62 = right ctrl
- } else if eventModifiers.contains(.shift) {
- actualKeyCode = (keyCode == 56) ? 56 : 60 // 56 = left shift, 60 = right shift
+
+ if eventModifiers.isEmpty {
+ if pendingModifierOnly, let modifierKeyCode = pendingModifierKeyCode {
+ let newShortcut = HotkeyShortcut(keyCode: modifierKeyCode, modifierFlags: [])
+ DebugLogger.shared.debug("NSEvent monitor: Recording modifier-only shortcut: \(newShortcut.displayString)", source: "ContentView")
+ hotkeyShortcut = newShortcut
+ SettingsStore.shared.hotkeyShortcut = newShortcut
+ hotkeyManager?.updateShortcut(newShortcut)
+ isRecordingShortcut = false
+ resetPendingShortcutState()
+ DebugLogger.shared.debug("NSEvent monitor: Finished recording modifier shortcut, isRecordingShortcut set to false", source: "ContentView")
+ return nil
}
-
- let newShortcut = HotkeyShortcut(keyCode: actualKeyCode, modifierFlags: [])
- DebugLogger.shared.debug("NSEvent monitor: Recording new shortcut (modifier only): \(newShortcut.displayString), original keyCode: \(keyCode), mapped keyCode: \(actualKeyCode)", source: "ContentView")
- hotkeyShortcut = newShortcut
- SettingsStore.shared.hotkeyShortcut = newShortcut
- hotkeyManager?.updateShortcut(newShortcut)
- isRecordingShortcut = false
- DebugLogger.shared.debug("NSEvent monitor: Finished recording modifier shortcut, isRecordingShortcut set to false", source: "ContentView")
+
+ resetPendingShortcutState()
+ DebugLogger.shared.debug("NSEvent monitor: Modifiers released without recording, continuing to wait", source: "ContentView")
return nil
}
+
+ // Modifiers are currently pressed
+ var actualKeyCode = event.keyCode
+ if eventModifiers.contains(.command) {
+ actualKeyCode = (event.keyCode == 55) ? 55 : 54 // 55 = left cmd, 54 = right cmd
+ } else if eventModifiers.contains(.option) {
+ actualKeyCode = (event.keyCode == 58) ? 58 : 61 // 58 = left opt, 61 = right opt
+ } else if eventModifiers.contains(.control) {
+ actualKeyCode = (event.keyCode == 59) ? 59 : 62 // 59 = left ctrl, 62 = right ctrl
+ } else if eventModifiers.contains(.shift) {
+ actualKeyCode = (event.keyCode == 56) ? 56 : 60 // 56 = left shift, 60 = right shift
+ }
+
+ pendingModifierFlags = eventModifiers
+ pendingModifierKeyCode = actualKeyCode
+ pendingModifierOnly = true
+ DebugLogger.shared.debug("NSEvent monitor: Modifier key pressed during recording, pending modifiers: \(pendingModifierFlags)", source: "ContentView")
+ return nil
}
return event
@@ -366,7 +388,14 @@ struct ContentView: View {
}
}
}
-
+
+ private func resetPendingShortcutState()
+ {
+ pendingModifierFlags = []
+ pendingModifierKeyCode = nil
+ pendingModifierOnly = false
+ }
+
private var sidebarView: some View {
List(selection: $selectedSidebarItem) {
NavigationLink(value: SidebarItem.welcome) {
diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swift
index 5dc583dc..5d78ba9b 100644
--- a/Sources/Fluid/Services/MenuBarManager.swift
+++ b/Sources/Fluid/Services/MenuBarManager.swift
@@ -6,6 +6,7 @@ import PromiseKit
final class MenuBarManager: ObservableObject {
private var statusItem: NSStatusItem?
private var menu: NSMenu?
+ private var isSetup: Bool = false
// References to app state
private weak var asrService: ASRService?
@@ -15,7 +16,7 @@ final class MenuBarManager: ObservableObject {
@Published var aiProcessingEnabled: Bool = false
init() {
- setupMenuBar()
+ // Don't setup menu bar immediately - defer until app is ready
// Initialize from persisted setting
aiProcessingEnabled = SettingsStore.shared.enableAIProcessing
// Reflect changes to menu when toggled from elsewhere (e.g., General tab)
@@ -27,6 +28,15 @@ final class MenuBarManager: ObservableObject {
.store(in: &cancellables)
}
+ func initializeMenuBar() {
+ guard !isSetup else { return }
+
+ // Ensure we're on main thread and app is active
+ DispatchQueue.main.async { [weak self] in
+ self?.setupMenuBarSafely()
+ }
+ }
+
deinit {
statusItem = nil
}
@@ -48,11 +58,38 @@ final class MenuBarManager: ObservableObject {
aiProcessingEnabled = SettingsStore.shared.enableAIProcessing
}
- private func setupMenuBar() {
- // Create status item
+ private func setupMenuBarSafely() {
+ // Check if window server connection is available
+ guard NSApp.isActive || NSApp.isRunning else {
+ // Retry after a short delay if app isn't ready
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
+ self?.setupMenuBarSafely()
+ }
+ return
+ }
+
+ do {
+ try setupMenuBar()
+ isSetup = true
+ } catch {
+ // If setup fails, retry after delay
+ print("MenuBar setup failed, retrying: \(error)")
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
+ self?.setupMenuBarSafely()
+ }
+ }
+ }
+
+ private func setupMenuBar() throws {
+ // Ensure we're not already set up
+ guard !isSetup else { return }
+
+ // Create status item with error handling
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
- guard let statusItem = statusItem else { return }
+ guard let statusItem = statusItem else {
+ throw NSError(domain: "MenuBarManager", code: 1, userInfo: [NSLocalizedDescriptionKey: "Failed to create status item"])
+ }
// Set initial icon
updateMenuBarIcon()