Skip to content

Commit

Permalink
Update ShortcutManager to handle the shortcut handler throwing now
Browse files Browse the repository at this point in the history
  • Loading branch information
tombell committed Jan 26, 2025
1 parent 3fb4d48 commit 8abec94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/skbdlib/ShortcutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public enum ShortcutManager {
return OSStatus(eventNotHandledErr)
}

shortcut.handler()
do {
try shortcut.handler()
} catch {
return OSStatus(eventInternalErr)
}

return noErr
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/skbdlibTests/ShortcutManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,20 @@ class ShortcutManagerTests {

#expect(status == OSStatus(eventNotHandledErr))
}

@Test("ShortcutManager.handleCarbonEvent() (with broken shortcut handler)")
func handleCarbonEventWithBrokenShortcutHandler() async throws {
setenv("SHELL", "/bin/invalid", 1)

let handler = Shortcut.handler(for: "true")
let shortcut = Shortcut(123, 456, handler)

ShortcutManager.register(shortcut: shortcut)
let box = try #require(ShortcutManager.box(for: shortcut))

let event = createEventRef(signature: skbdEventHotKeySignature, id: box.eventHotKeyID)
let status = ShortcutManager.handleCarbonEvent(event)

#expect(status == OSStatus(eventInternalErr))
}
}

0 comments on commit 8abec94

Please sign in to comment.