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(hotkey): preserve mouse press lifecycle
altic-dev1fd51e4e33a4
diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swiftindex 2e41480b..32fc3b7e 100644--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift@@ -656,6 +656,7 @@ final class GlobalHotkeyManager: NSObject {@discardableResultprivate func setupGlobalHotkey() -> Bool {+ self.finishInterruptedMouseShortcutPress(reason: "hotkey tap reinitialized")self.cleanupEventTap()if !AXIsProcessTrusted() {@@ -894,6 +895,7 @@ final class GlobalHotkeyManager: NSObject {// Filter tap, created only for the button families that have a shortcut.private func setupMouseShortcutTap(mouseButtons: Set<Int>) {+ self.finishInterruptedMouseShortcutPress(reason: "mouse shortcut tap rebuilt")self.cleanupMouseShortcutTap()let mask = Self.mouseShortcutEventMask(mouseButtons: mouseButtons)@@ -982,7 +984,7 @@ final class GlobalHotkeyManager: NSObject {private func handleMouseShortcutEvent(type: CGEventType, event: CGEvent) -> Unmanaged<CGEvent>? {if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {- self.clearPrimaryShortcutPressState(mouseOnly: true)+ self.finishInterruptedMouseShortcutPress(reason: "mouse shortcut tap disabled")self.reenableMouseTap(self.mouseShortcutTap, label: "Mouse shortcut") {self.setupMouseShortcutTap(mouseButtons: self.configuredMouseButtons())}@@ -1070,6 +1072,18 @@ final class GlobalHotkeyManager: NSObject {}}+ private func finishInterruptedMouseShortcutPress(reason: String) {+ guard case let .mouse(mouseButton)? = self.activePrimaryShortcutPress,+ self.finishPrimaryShortcutPress(.mouse(mouseButton))+ else { return }++ DebugLogger.shared.warning(+ "Finishing active mouse shortcut press before \(reason)",+ source: "GlobalHotkeyManager"+ )+ self.handlePrimaryDictationTriggerUp()+ }+private func finishPrimaryShortcutPress(_ press: ActivePrimaryShortcutPress) -> Bool {self.state.withLock {guard self.state.activePrimaryShortcutPress == press else {@@ -2119,7 +2133,7 @@ final class GlobalHotkeyManager: NSObject {}if self.primaryShortcuts.contains(where: { $0.matchesMouse(button: mouseButton, modifiers: eventModifiers) }) {- guard self.beginPrimaryShortcutPress(.mouse(mouseButton)) else { return true }+ guard self.beginPrimaryShortcutPress(.mouse(mouseButton)) else { return false }self.handlePrimaryDictationTriggerDown()return true}diff --git a/Sources/Fluid/Views/AutomaticDictionaryCorrectionOverlay.swift b/Sources/Fluid/Views/AutomaticDictionaryCorrectionOverlay.swiftindex 338ef351..a9576e10 100644--- a/Sources/Fluid/Views/AutomaticDictionaryCorrectionOverlay.swift+++ b/Sources/Fluid/Views/AutomaticDictionaryCorrectionOverlay.swift@@ -243,6 +243,10 @@ final class MicrophoneChangeOverlayController {static let shared = MicrophoneChangeOverlayController()private static let displayDurationNanoseconds: UInt64 = 5_000_000_000+ private static let supportedBundleIdentifiers = [+ "com.FluidApp.app",+ "com.FluidApp.app.debug",+ ]private var panel: NSPanel?private var hostingView: NSHostingView<MicrophoneChangeOverlayView>?private var dismissTask: Task<Void, Never>?@@ -251,7 +255,7 @@ final class MicrophoneChangeOverlayController {private init() {}func show(_ notice: MicrophoneChangeNotice) {- guard Bundle.main.bundleIdentifier == "com.FluidApp.app",+ guard Self.supportsAlerts(bundleIdentifier: Bundle.main.bundleIdentifier),SettingsStore.shared.showMicrophoneChangeAlertselse { return }self.generation &+= 1@@ -300,6 +304,11 @@ final class MicrophoneChangeOverlayController {}}+ nonisolated static func supportsAlerts(bundleIdentifier: String?) -> Bool {+ guard let bundleIdentifier else { return false }+ return self.supportedBundleIdentifiers.contains(bundleIdentifier)+ }+func disableFutureAlerts() {SettingsStore.shared.showMicrophoneChangeAlerts = falseself.hide()diff --git a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swiftindex 4d8a448b..98f1ae06 100644--- a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift+++ b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift@@ -101,6 +101,13 @@ final class HotkeyShortcutTests: XCTestCase {XCTAssertNil(replay.activeModifierOnlyType)}+ func testMicrophoneChangeAlertsSupportProductionAndDebugAppsOnly() {+ XCTAssertTrue(MicrophoneChangeOverlayController.supportsAlerts(bundleIdentifier: "com.FluidApp.app"))+ XCTAssertTrue(MicrophoneChangeOverlayController.supportsAlerts(bundleIdentifier: "com.FluidApp.app.debug"))+ XCTAssertFalse(MicrophoneChangeOverlayController.supportsAlerts(bundleIdentifier: "com.example.tests"))+ XCTAssertFalse(MicrophoneChangeOverlayController.supportsAlerts(bundleIdentifier: nil))+ }+func testHotkeySessionLockDetection() {XCTAssertTrue(GlobalHotkeyManager.sessionIsLocked(sessionInfo: ["CGSSessionScreenIsLocked": true]))XCTAssertFalse(GlobalHotkeyManager.sessionIsLocked(sessionInfo: ["CGSSessionScreenIsLocked": false]))