Skip to content

Commit

Permalink
fix: restart ineffective keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Celve committed Feb 22, 2025
1 parent b87b928 commit 1745820
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Peninsula/Events/HotKeyObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,16 @@ class HotKeyObserver {
callback: { (proxy, type, event, refcon) -> Unmanaged<CGEvent>? in
// Retrieve the CurrentValueSubject instance from the unmanaged pointer
let this = Unmanaged<HotKeyObserver>.fromOpaque(refcon!).takeUnretainedValue()
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
let flags = event.flags
for toggle in this.toggles {
if toggle.process(globalState: &this.state, type: type, keyCode: Int(keyCode), flags: flags) {
return nil

if (type == .tapDisabledByUserInput || type == .tapDisabledByTimeout) {
CGEvent.tapEnable(tap: this.eventTap!, enable: true)
} else {
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
let flags = event.flags
for toggle in this.toggles {
if toggle.process(globalState: &this.state, type: type, keyCode: Int(keyCode), flags: flags) {
return nil
}
}
}

Expand All @@ -165,6 +170,7 @@ class HotKeyObserver {
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
CGEvent.tapEnable(tap: eventTap, enable: true)
print("Succeeded to create event tap")
} else {
print("Failed to create event tap")
}
Expand Down

0 comments on commit 1745820

Please sign in to comment.