Repository navigation
fix: retry re-enabling event tap after wake if it fails - #5
Open
lovestorms wants to merge 1 commit into
Open
lovestorms wants to merge 1 commit into
lovestorms wants to merge 1 commit into
Conversation
startEventTap() can fail right after the Mac wakes from sleep even though AXIsProcessTrusted() reports true later, because macOS briefly reinstates the Accessibility permission asynchronously. receiveWake() used to call startEventTap() once and silently drop the failure, which left Vietnamese typing dead until the app was relaunched. Retry a few times with a short delay instead of giving up on the first failure. Fix by Duc Do
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After the Mac wakes from sleep (or sometimes after locking/unlocking the screen), MKey can stop typing Vietnamese diacritics entirely. The only reliable fix without this patch is quitting and relaunching the app.
Root cause
receiveWake()inMkeyApp.swiftcalledMKBridge.startEventTap()exactly once and silently dropped the return value:Right after wake,
AXIsProcessTrusted()can reporttruewhile macOS hasn't fully reinstated the underlying Accessibility/event-tap permission yet, soCGEventTapCreateinsidestartEventTapfails and returnsNO. UnlikestartEngine()(used at launch), which checks the return value and falls back toaskForAccessibility(),receiveWake()had no retry path — so the event tap was simply never recreated until the app was relaunched.This matches symptoms reported upstream against the shared OpenKey engine:
kCGEventTapDisabledByTimeoutrecovery path, whichMKEngineHook.mmalready handles — this PR fixes the separate wake-time creation failure, which that one doesn't cover)Fix
Retry
startEventTap()a few times (0.5s apart, up to 5 attempts) instead of giving up after the first failure on wake:Testing
xcodegen generate+xcodebuild -project mkey.xcodeproj -scheme mkey -configuration Debug build→ BUILD SUCCEEDED.CGEventTapCreateactually fails here.Fix by Duc Do