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

Fix shortcut migration conflicts

altic-devcca2fb65a339
diff --git a/Sources/Fluid/Models/HotkeyShortcut.swift b/Sources/Fluid/Models/HotkeyShortcut.swift
index 0621a0a0..17d39e00 100644
--- a/Sources/Fluid/Models/HotkeyShortcut.swift
+++ b/Sources/Fluid/Models/HotkeyShortcut.swift
@@ -237,18 +237,35 @@ extension HotkeyShortcut {
return Self.modifierFlag(forKeyCode: self.keyCode)
}
- /// True when two modifier-only shortcuts would overlap — either identical
- /// or one is a subset of the other's modifiers (e.g. ⌥ vs ⌥+⇧). Prevents
- /// the shared `modifierOnlyKeyDown` release race in GlobalHotkeyManager.
+ /// True when shortcut presses can race because one begins as the other's modifier prefix.
func conflictsWith(_ other: HotkeyShortcut) -> Bool {
- guard self.isModifierOnlyShortcut, other.isModifierOnlyShortcut else { return false }
+ if self.isModifierOnlyShortcut, other.isModifierOnlyShortcut {
+ let lhs = Set(self.normalizedModifierKeyCodes)
+ let rhs = Set(other.normalizedModifierKeyCodes)
- let lhs = Set(self.normalizedModifierKeyCodes)
- let rhs = Set(other.normalizedModifierKeyCodes)
+ guard !lhs.isEmpty, !rhs.isEmpty else { return false }
- guard !lhs.isEmpty, !rhs.isEmpty else { return false }
+ return lhs.isSubset(of: rhs) || rhs.isSubset(of: lhs)
+ }
+
+ if self.isMouseShortcut, other.isModifierOnlyShortcut {
+ return self.mouseModifiersOverlap(modifierOnlyShortcut: other)
+ }
+
+ if other.isMouseShortcut, self.isModifierOnlyShortcut {
+ return other.mouseModifiersOverlap(modifierOnlyShortcut: self)
+ }
+
+ return false
+ }
+
+ private func mouseModifiersOverlap(modifierOnlyShortcut: HotkeyShortcut) -> Bool {
+ guard self.isMouseShortcut,
+ let expectedModifiers = modifierOnlyShortcut.expectedModifierFlags,
+ !expectedModifiers.isEmpty
+ else { return false }
- return lhs.isSubset(of: rhs) || rhs.isSubset(of: lhs)
+ return expectedModifiers.isSubset(of: self.relevantModifierFlags)
}
var isModifierOnlyShortcut: Bool {
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index 24d3340a..936f530e 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -30,6 +30,7 @@ final class SettingsStore: ObservableObject {
self.migrateDictationPromptProfilesIfNeeded()
self.migrateLegacyDictationAIPreferenceIfNeeded()
self.migrateSecondaryPromptShortcutIfNeeded()
+ self.retireLegacySecondaryPromptShortcutIfNeeded()
self.normalizePromptSelectionsIfNeeded()
self.normalizeProviderSelectionForCurrentVerificationState()
self.enforceOnboardingGenerationIfNeeded()
@@ -2981,6 +2982,16 @@ final class SettingsStore: ObservableObject {
self.defaults.set(true, forKey: Keys.secondaryPromptShortcutRemoved)
}
+ private func retireLegacySecondaryPromptShortcutIfNeeded() {
+ guard self.defaults.bool(forKey: Keys.legacySecondaryPromptShortcutRetired) == false else { return }
+
+ self.defaults.set(false, forKey: Keys.promptModeShortcutEnabled)
+ self.defaults.set(true, forKey: Keys.secondaryDictationPromptOff)
+ self.defaults.removeObject(forKey: Keys.promptModeHotkeyShortcut)
+ self.defaults.removeObject(forKey: Keys.promptModeSelectedPromptID)
+ self.defaults.set(true, forKey: Keys.legacySecondaryPromptShortcutRetired)
+ }
+
private func normalizePromptSelectionsIfNeeded() {
if self.defaults.object(forKey: Keys.secondaryDictationPromptOff) == nil {
self.defaults.set(false, forKey: Keys.secondaryDictationPromptOff)
@@ -4311,6 +4322,7 @@ private extension SettingsStore {
static let promptModeSelectedPromptID = "PromptModeSelectedPromptID"
static let secondaryDictationPromptOff = "SecondaryDictationPromptOff"
static let secondaryPromptShortcutRemoved = "SecondaryPromptShortcutRemoved"
+ static let legacySecondaryPromptShortcutRetired = "LegacySecondaryPromptShortcutRetired"
static let dictationPromptConfigurations = "DictationPromptConfigurations"
// Rewrite Mode Keys
diff --git a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
index 25886def..a0e3f4ec 100644
--- a/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
+++ b/Tests/FluidDictationIntegrationTests/HotkeyShortcutTests.swift
@@ -72,6 +72,16 @@ final class HotkeyShortcutTests: XCTestCase {
XCTAssertNotEqual(mouseShortcut, keyboardShortcut)
}
+ func testModifiedMouseShortcutConflictsWithModifierOnlyShortcut() {
+ let optionOnly = HotkeyShortcut(keyCode: 61, modifierFlags: [])
+ let modifiedClick = HotkeyShortcut(mouseButton: 0, modifierFlags: [.option])
+ let unmodifiedSideButton = HotkeyShortcut(mouseButton: 3, modifierFlags: [])
+
+ XCTAssertTrue(modifiedClick.conflictsWith(optionOnly))
+ XCTAssertTrue(optionOnly.conflictsWith(modifiedClick))
+ XCTAssertFalse(unmodifiedSideButton.conflictsWith(optionOnly))
+ }
+
func testPrimaryDictationShortcutsFallbackToLegacyShortcut() throws {
try self.withRestoredDefaults(keys: [self.legacyHotkeyShortcutKey, self.primaryDictationShortcutsKey]) {
let legacyShortcut = HotkeyShortcut(keyCode: 12, modifierFlags: [.option])