fix: trust native global shortcut registration
This commit is contained in:
@@ -89,36 +89,14 @@ public final class GlobalShortcut {
|
||||
if let registration {
|
||||
try registration.activate(candidate)
|
||||
} else {
|
||||
try Self.rejectSystemConflict(candidate)
|
||||
try native.register(candidate)
|
||||
}
|
||||
isRegistered = true
|
||||
}
|
||||
|
||||
private static func rejectSystemConflict(_ candidate: KeyboardShortcut) throws {
|
||||
var copied: Unmanaged<CFArray>?
|
||||
let status = CopySymbolicHotKeys(&copied)
|
||||
let result = copied?.takeRetainedValue()
|
||||
guard status == noErr, let result else {
|
||||
throw ShortcutError.native(operation: "read macOS keyboard shortcuts", status: status)
|
||||
}
|
||||
let hotKeys = result as NSArray
|
||||
for case let record as NSDictionary in hotKeys {
|
||||
guard let enabled = record[kHISymbolicHotKeyEnabled] as? NSNumber, enabled.boolValue,
|
||||
let code = record[kHISymbolicHotKeyCode] as? NSNumber,
|
||||
let modifiers = record[kHISymbolicHotKeyModifiers] as? NSNumber else { continue }
|
||||
let relevantModifiers = UInt32(cmdKey | optionKey | controlKey | shiftKey)
|
||||
if code.uint16Value == candidate.keyCode,
|
||||
modifiers.uint32Value & relevantModifiers == candidate.carbonModifiers {
|
||||
throw ShortcutError.systemConflict(candidate.displayName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ShortcutError: LocalizedError {
|
||||
case invalidSavedShortcut
|
||||
case systemConflict(String)
|
||||
case inAppConflict(shortcut: String, action: String)
|
||||
case duplicate(shortcut: String, destination: String)
|
||||
case native(operation: String, status: OSStatus)
|
||||
@@ -127,8 +105,6 @@ enum ShortcutError: LocalizedError {
|
||||
switch self {
|
||||
case .invalidSavedShortcut:
|
||||
return "The saved shortcut is invalid. Choose a new shortcut or clear it in Conjure Settings."
|
||||
case .systemConflict(let shortcut):
|
||||
return "\(shortcut) is already an enabled macOS shortcut. Check System Settings → Keyboard → Keyboard Shortcuts, including Spotlight and Input Sources. On macOS 27, Command-Shift-Space is also reserved for Siri AI screen capture. Choose another shortcut or change the system binding; Conjure will not change your system settings."
|
||||
case .inAppConflict(let shortcut, let action):
|
||||
return "\(shortcut) is already used by Conjure for \(action). Choose another shortcut."
|
||||
case .duplicate(let shortcut, let destination):
|
||||
|
||||
Reference in New Issue
Block a user