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
Fix shortcut reassignment capture flow
altic-dev73a9910d5f5b
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex 31a52fd8..1eb4835b 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -97,6 +97,7 @@ struct ContentView: View {@State private var pendingModifierFlags: NSEvent.ModifierFlags = []@State private var pendingModifierKeyCode: UInt16?@State private var pendingModifierOnly = false+ @State private var shortcutRecordingMessage: String? = nil@FocusState private var isTranscriptionFocused: Bool@State private var selectedSidebarItem: SidebarItem?@@ -371,19 +372,16 @@ struct ContentView: View {self.isRecordingCommandModeShortcut ||self.isRecordingRewriteShortcut ||self.isRecordingCancelShortcut+ let recordingTarget = self.currentShortcutRecordingTarget()if event.type == .keyDown {- if self.hotkeyShortcut.matches(keyCode: event.keyCode, modifiers: eventModifiers) {- DebugLogger.shared.debug("NSEvent monitor: Global hotkey matched on keyDown, passing event through (GlobalHotkeyManager handles)", source: "ContentView")- return event- }-guard isRecordingAnyShortcut else {if self.cancelRecordingHotkeyShortcut.matches(keyCode: event.keyCode, modifiers: eventModifiers),self.handleCancelShortcut(){return nil}+ self.shortcutRecordingMessage = nilself.resetPendingShortcutState()return event}@@ -391,12 +389,7 @@ struct ContentView: View {let keyCode = event.keyCodeif keyCode == 53 && !self.isRecordingCancelShortcut {DebugLogger.shared.debug("NSEvent monitor: Escape pressed, cancelling shortcut recording", source: "ContentView")- self.isRecordingShortcut = false- self.isRecordingPromptModeShortcut = false- self.isRecordingCommandModeShortcut = false- self.isRecordingRewriteShortcut = false- self.isRecordingCancelShortcut = false- self.resetPendingShortcutState()+ self.clearShortcutRecordingMode()return nil}@@ -404,44 +397,25 @@ struct ContentView: View {let newShortcut = HotkeyShortcut(keyCode: keyCode, modifierFlags: combinedModifiers)DebugLogger.shared.debug("NSEvent monitor: Recording new shortcut: \(newShortcut.displayString)", source: "ContentView")- if self.isRecordingRewriteShortcut {- self.rewriteModeHotkeyShortcut = newShortcut- SettingsStore.shared.rewriteModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updateRewriteModeShortcut(newShortcut)- self.isRecordingRewriteShortcut = false- } else if self.isRecordingCancelShortcut {- self.cancelRecordingHotkeyShortcut = newShortcut- SettingsStore.shared.cancelRecordingHotkeyShortcut = newShortcut- self.isRecordingCancelShortcut = false- } else if self.isRecordingPromptModeShortcut {- self.promptModeHotkeyShortcut = newShortcut- SettingsStore.shared.promptModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updatePromptModeShortcut(newShortcut)- self.isRecordingPromptModeShortcut = false- } else if self.isRecordingCommandModeShortcut {- self.commandModeHotkeyShortcut = newShortcut- SettingsStore.shared.commandModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updateCommandModeShortcut(newShortcut)- self.isRecordingCommandModeShortcut = false- } else {- self.hotkeyShortcut = newShortcut- SettingsStore.shared.hotkeyShortcut = newShortcut- self.hotkeyManager?.updateShortcut(newShortcut)- self.isRecordingShortcut = false+ if let recordingTarget,+ let conflictMessage = self.shortcutConflictMessage(for: newShortcut, target: recordingTarget)+ {+ self.shortcutRecordingMessage = conflictMessage+ self.resetPendingShortcutState()+ DebugLogger.shared.debug("NSEvent monitor: Shortcut conflict while recording: \(conflictMessage)", source: "ContentView")+ return nil+ }++ self.shortcutRecordingMessage = nil+ if let recordingTarget {+ self.assignRecordedShortcut(newShortcut, to: recordingTarget)}self.resetPendingShortcutState()DebugLogger.shared.debug("NSEvent monitor: Finished recording shortcut", source: "ContentView")return nil} else if event.type == .flagsChanged {- if self.hotkeyShortcut.modifierFlags.isEmpty {- let isModifierKeyPressed = eventModifiers.isEmpty == false- if event.keyCode == self.hotkeyShortcut.keyCode && isModifierKeyPressed {- DebugLogger.shared.debug("NSEvent monitor: Global hotkey matched on flagsChanged, passing event through (GlobalHotkeyManager handles)", source: "ContentView")- return event- }- }-guard isRecordingAnyShortcut else {+ self.shortcutRecordingMessage = nilself.resetPendingShortcutState()return event}@@ -451,30 +425,18 @@ struct ContentView: View {let newShortcut = HotkeyShortcut(keyCode: modifierKeyCode, modifierFlags: [])DebugLogger.shared.debug("NSEvent monitor: Recording modifier-only shortcut: \(newShortcut.displayString)", source: "ContentView")- if self.isRecordingRewriteShortcut {- self.rewriteModeHotkeyShortcut = newShortcut- SettingsStore.shared.rewriteModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updateRewriteModeShortcut(newShortcut)- self.isRecordingRewriteShortcut = false- } else if self.isRecordingCancelShortcut {- self.cancelRecordingHotkeyShortcut = newShortcut- SettingsStore.shared.cancelRecordingHotkeyShortcut = newShortcut- self.isRecordingCancelShortcut = false- } else if self.isRecordingPromptModeShortcut {- self.promptModeHotkeyShortcut = newShortcut- SettingsStore.shared.promptModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updatePromptModeShortcut(newShortcut)- self.isRecordingPromptModeShortcut = false- } else if self.isRecordingCommandModeShortcut {- self.commandModeHotkeyShortcut = newShortcut- SettingsStore.shared.commandModeHotkeyShortcut = newShortcut- self.hotkeyManager?.updateCommandModeShortcut(newShortcut)- self.isRecordingCommandModeShortcut = false- } else {- self.hotkeyShortcut = newShortcut- SettingsStore.shared.hotkeyShortcut = newShortcut- self.hotkeyManager?.updateShortcut(newShortcut)- self.isRecordingShortcut = false+ if let recordingTarget,+ let conflictMessage = self.shortcutConflictMessage(for: newShortcut, target: recordingTarget)+ {+ self.shortcutRecordingMessage = conflictMessage+ self.resetPendingShortcutState()+ DebugLogger.shared.debug("NSEvent monitor: Modifier shortcut conflict while recording: \(conflictMessage)", source: "ContentView")+ return nil+ }++ self.shortcutRecordingMessage = nil+ if let recordingTarget {+ self.assignRecordedShortcut(newShortcut, to: recordingTarget)}self.resetPendingShortcutState()DebugLogger.shared.debug("NSEvent monitor: Finished recording modifier shortcut", source: "ContentView")@@ -781,6 +743,80 @@ struct ContentView: View {self.pendingModifierOnly = false}+ private enum ShortcutRecordingTarget {+ case primaryDictation+ case secondaryDictation+ case command+ case edit+ case cancel+ }++ private func currentShortcutRecordingTarget() -> ShortcutRecordingTarget? {+ if self.isRecordingShortcut { return .primaryDictation }+ if self.isRecordingPromptModeShortcut { return .secondaryDictation }+ if self.isRecordingCommandModeShortcut { return .command }+ if self.isRecordingRewriteShortcut { return .edit }+ if self.isRecordingCancelShortcut { return .cancel }+ return nil+ }++ private func shortcutConflictMessage(for shortcut: HotkeyShortcut, target: ShortcutRecordingTarget) -> String? {+ let configuredShortcuts: [(ShortcutRecordingTarget, String, HotkeyShortcut)] = [+ (.primaryDictation, "Primary Dictation Shortcut", self.hotkeyShortcut),+ (.secondaryDictation, "Secondary Dictation Shortcut", self.promptModeHotkeyShortcut),+ (.command, "Command Mode", self.commandModeHotkeyShortcut),+ (.edit, "Edit Mode", self.rewriteModeHotkeyShortcut),+ (.cancel, "Cancel Recording", self.cancelRecordingHotkeyShortcut),+ ]++ for (otherTarget, title, configuredShortcut) in configuredShortcuts where otherTarget != target {+ if configuredShortcut == shortcut {+ return "Duplicate with \(title)"+ }+ }++ return nil+ }++ private func assignRecordedShortcut(_ shortcut: HotkeyShortcut, to target: ShortcutRecordingTarget) {+ switch target {+ case .primaryDictation:+ self.hotkeyShortcut = shortcut+ SettingsStore.shared.hotkeyShortcut = shortcut+ self.hotkeyManager?.updateShortcut(shortcut)+ self.isRecordingShortcut = false+ case .secondaryDictation:+ self.promptModeHotkeyShortcut = shortcut+ SettingsStore.shared.promptModeHotkeyShortcut = shortcut+ self.hotkeyManager?.updatePromptModeShortcut(shortcut)+ self.isRecordingPromptModeShortcut = false+ case .command:+ self.commandModeHotkeyShortcut = shortcut+ SettingsStore.shared.commandModeHotkeyShortcut = shortcut+ self.hotkeyManager?.updateCommandModeShortcut(shortcut)+ self.isRecordingCommandModeShortcut = false+ case .edit:+ self.rewriteModeHotkeyShortcut = shortcut+ SettingsStore.shared.rewriteModeHotkeyShortcut = shortcut+ self.hotkeyManager?.updateRewriteModeShortcut(shortcut)+ self.isRecordingRewriteShortcut = false+ case .cancel:+ self.cancelRecordingHotkeyShortcut = shortcut+ SettingsStore.shared.cancelRecordingHotkeyShortcut = shortcut+ self.isRecordingCancelShortcut = false+ }+ }++ private func clearShortcutRecordingMode() {+ self.isRecordingShortcut = false+ self.isRecordingPromptModeShortcut = false+ self.isRecordingCommandModeShortcut = false+ self.isRecordingRewriteShortcut = false+ self.isRecordingCancelShortcut = false+ self.shortcutRecordingMessage = nil+ self.resetPendingShortcutState()+ }+private func openIssueReportingPage() {guard let url = URL(string: "https://github.com/altic-dev/Fluid-oss/issues/new/choose") else { return }NSWorkspace.shared.open(url)@@ -1122,6 +1158,7 @@ struct ContentView: View {accessibilityEnabled: self.$accessibilityEnabled,hotkeyShortcut: self.$hotkeyShortcut,isRecordingShortcut: self.$isRecordingShortcut,+ shortcutRecordingMessage: self.$shortcutRecordingMessage,promptModeShortcut: self.$promptModeHotkeyShortcut,isRecordingPromptModeShortcut: self.$isRecordingPromptModeShortcut,promptModeShortcutEnabled: self.$isPromptModeShortcutEnabled,@@ -2472,6 +2509,13 @@ struct ContentView: View {},isRewriteRecordingProvider: {self.activeRecordingMode == .edit+ },+ isShortcutCaptureActiveProvider: {+ self.isRecordingShortcut ||+ self.isRecordingPromptModeShortcut ||+ self.isRecordingCommandModeShortcut ||+ self.isRecordingRewriteShortcut ||+ self.isRecordingCancelShortcut})diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swiftindex d64277ca..38b156cd 100644--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift@@ -50,6 +50,7 @@ final class GlobalHotkeyManager: NSObject {private var isPromptModeRecordingProvider: (() -> Bool)?private var isCommandRecordingProvider: (() -> Bool)?private var isRewriteRecordingProvider: (() -> Bool)?+ private var isShortcutCaptureActiveProvider: (() -> Bool)?private var cancelCallback: (() -> Bool)? // Returns true if handledprivate var pressAndHoldMode: Bool = SettingsStore.shared.pressAndHoldMode@@ -129,7 +130,8 @@ final class GlobalHotkeyManager: NSObject {isDictateRecordingProvider: (() -> Bool)? = nil,isPromptModeRecordingProvider: (() -> Bool)? = nil,isCommandRecordingProvider: (() -> Bool)? = nil,- isRewriteRecordingProvider: (() -> Bool)? = nil+ isRewriteRecordingProvider: (() -> Bool)? = nil,+ isShortcutCaptureActiveProvider: (() -> Bool)? = nil) {self.asrService = asrServiceself.shortcut = shortcut@@ -149,6 +151,7 @@ final class GlobalHotkeyManager: NSObject {self.isPromptModeRecordingProvider = isPromptModeRecordingProviderself.isCommandRecordingProvider = isCommandRecordingProviderself.isRewriteRecordingProvider = isRewriteRecordingProvider+ self.isShortcutCaptureActiveProvider = isShortcutCaptureActiveProvidersuper.init()self.initializeWithDelay()@@ -330,26 +333,11 @@ final class GlobalHotkeyManager: NSObject {}private func handleKeyEvent(proxy: CGEventTapProxy, type: CGEventType, event: CGEvent) -> Unmanaged<CGEvent>? {- // macOS can temporarily disable event taps (e.g. timeouts, user input protection).- // If we don't immediately re-enable here, hotkeys will silently stop working until our- // periodic health check kicks in, and the OS may handle the key (e.g. system dictation).- if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {- let reason = (type == .tapDisabledByTimeout) ? "timeout" : "user input"- DebugLogger.shared.warning("Event tap disabled by \(reason) — attempting immediate re-enable", source: "GlobalHotkeyManager")-- if let tap = self.eventTap {- CGEvent.tapEnable(tap: tap, enable: true)- }-- // If re-enable failed, recreate the tap.- if !self.isEventTapEnabled() {- DebugLogger.shared.warning("Event tap re-enable failed — recreating tap", source: "GlobalHotkeyManager")- self.setupGlobalHotkeyWithRetry()- }+ if let tapRecoveryResult = self.handleTapDisableEvent(type: type, event: event) {+ return tapRecoveryResult+ }- // CRITICAL: Return the event to let it pass through during recovery.- // Previously returning nil would consume/block all keyboard events- // (including CGEvent text insertion) during the recovery period.+ if self.isShortcutCaptureActiveProvider?() ?? false {return Unmanaged.passUnretained(event)}@@ -789,6 +777,29 @@ final class GlobalHotkeyManager: NSObject {return Unmanaged.passUnretained(event)}+ private func handleTapDisableEvent(type: CGEventType, event: CGEvent) -> Unmanaged<CGEvent>? {+ // macOS can temporarily disable event taps (e.g. timeouts, user input protection).+ // If we don't immediately re-enable here, hotkeys will silently stop working until our+ // periodic health check kicks in, and the OS may handle the key (e.g. system dictation).+ guard type == .tapDisabledByTimeout || type == .tapDisabledByUserInput else {+ return nil+ }++ let reason = (type == .tapDisabledByTimeout) ? "timeout" : "user input"+ DebugLogger.shared.warning("Event tap disabled by \(reason) — attempting immediate re-enable", source: "GlobalHotkeyManager")++ if let tap = self.eventTap {+ CGEvent.tapEnable(tap: tap, enable: true)+ }++ if !self.isEventTapEnabled() {+ DebugLogger.shared.warning("Event tap re-enable failed — recreating tap", source: "GlobalHotkeyManager")+ self.setupGlobalHotkeyWithRetry()+ }++ return Unmanaged.passUnretained(event)+ }+private func handlePromptModeKeyDown(keyCode: UInt16, modifiers: NSEvent.ModifierFlags) -> Bool {guard self.promptModeShortcutEnabled, self.matchesPromptModeShortcut(keyCode: keyCode, modifiers: modifiers) else { return false }if self.pressAndHoldMode {diff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swiftindex f6dfcc4f..14a6804d 100644--- a/Sources/Fluid/UI/SettingsView.swift+++ b/Sources/Fluid/UI/SettingsView.swift@@ -28,6 +28,7 @@ struct SettingsView: View {@Binding var accessibilityEnabled: Bool@Binding var hotkeyShortcut: HotkeyShortcut@Binding var isRecordingShortcut: Bool+ @Binding var shortcutRecordingMessage: String?@Binding var promptModeShortcut: HotkeyShortcut@Binding var isRecordingPromptModeShortcut: Bool@Binding var promptModeShortcutEnabled: Bool@@ -630,8 +631,10 @@ struct SettingsView: View {description: "Defaults to raw transcription, but can use Off, Default, or any custom prompt.",shortcut: self.hotkeyShortcut,isRecording: self.isRecordingShortcut,+ recordingMessage: self.isRecordingShortcut ? self.shortcutRecordingMessage : nil,onChangePressed: {DebugLogger.shared.debug("Starting to record new transcribe shortcut", source: "SettingsView")+ self.shortcutRecordingMessage = nilself.isRecordingShortcut = true})@@ -645,9 +648,11 @@ struct SettingsView: View {description: "Defaults to Default cleanup, but can use Off, Default, or any custom prompt.",shortcut: self.promptModeShortcut,isRecording: self.isRecordingPromptModeShortcut,+ recordingMessage: self.isRecordingPromptModeShortcut ? self.shortcutRecordingMessage : nil,isEnabled: self.$promptModeShortcutEnabled,onChangePressed: {DebugLogger.shared.debug("Starting to record new prompt mode shortcut", source: "SettingsView")+ self.shortcutRecordingMessage = nilself.isRecordingPromptModeShortcut = true})@@ -665,9 +670,11 @@ struct SettingsView: View {description: "Execute voice commands",shortcut: self.commandModeShortcut,isRecording: self.isRecordingCommandModeShortcut,+ recordingMessage: self.isRecordingCommandModeShortcut ? self.shortcutRecordingMessage : nil,isEnabled: self.$commandModeShortcutEnabled,onChangePressed: {DebugLogger.shared.debug("Starting to record new command mode shortcut", source: "SettingsView")+ self.shortcutRecordingMessage = nilself.isRecordingCommandModeShortcut = true})@@ -680,9 +687,11 @@ struct SettingsView: View {description: "Select text and speak how to edit, or generate new content",shortcut: self.rewriteShortcut,isRecording: self.isRecordingRewriteShortcut,+ recordingMessage: self.isRecordingRewriteShortcut ? self.shortcutRecordingMessage : nil,isEnabled: self.$rewriteShortcutEnabled,onChangePressed: {DebugLogger.shared.debug("Starting to record new write mode shortcut", source: "SettingsView")+ self.shortcutRecordingMessage = nilself.isRecordingRewriteShortcut = true})@@ -695,8 +704,10 @@ struct SettingsView: View {description: "Cancel the current recording or dismiss the active recording overlay",shortcut: self.cancelRecordingShortcut,isRecording: self.isRecordingCancelShortcut,+ recordingMessage: self.isRecordingCancelShortcut ? self.shortcutRecordingMessage : nil,onChangePressed: {DebugLogger.shared.debug("Starting to record new cancel shortcut", source: "SettingsView")+ self.shortcutRecordingMessage = nilself.isRecordingCancelShortcut = true})@@ -1683,6 +1694,7 @@ struct SettingsView: View {description: String,shortcut: HotkeyShortcut,isRecording: Bool,+ recordingMessage: String? = nil,isEnabled: Binding<Bool>? = nil,onChangePressed: @escaping () -> Void) -> some View {@@ -1748,6 +1760,12 @@ struct SettingsView: View {.buttonStyle(.bordered).controlSize(.small).disabled(isRecording || !enabledValue)++ if isRecording, let recordingMessage, !recordingMessage.isEmpty {+ Text(recordingMessage)+ .font(.caption)+ .foregroundStyle(self.theme.palette.warning)+ }}}.opacity(enabledValue ? 1 : 0.7)