fix: auto-detect accessibility permission changes without restart - #64
Merged
Merged
Conversation
Add a periodic permission polling timer (every 3 seconds) that detects when the user grants Accessibility or Input Monitoring permissions in System Settings. Previously, these permissions required a manual app restart or clicking 'Recheck Permissions' to be detected. Changes: - Add permissionPollTimer that polls checkPermissions() every 3 seconds - Start polling on app startup if any permission is missing - Start polling when user requests a permission (opens System Settings) - Auto-stop polling once all permissions are granted (no wasted cycles) - Auto-start the hotkey listener when permissions are granted mid-session - Replace one-shot delayed rechecks with continuous polling - Add allPermissionsGranted computed property for clean stop condition
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 reinstalling VocaMac (which resets ad-hoc signing permissions), granting Accessibility permission in System Settings was not reflected in the app until the user either:
Microphone permission worked instantly (callback-based API), but Accessibility and Input Monitoring use
AXIsProcessTrustedWithOptionsandCGEvent.tapCreaterespectively — neither has a callback or notification mechanism.Solution
Add a lightweight permission polling timer that checks all permissions every 3 seconds until they're all granted.
How it works
checkPermissions()to refresh all three permission statesChanges (
AppState.swift)permissionPollTimerpropertystartPermissionPolling()— creates a 3-second repeating timer, guarded against duplicate starts and skipped if all permissions are already grantedstopPermissionPolling()— invalidates and nils the timerallPermissionsGrantedcomputed property for clean stop conditionDispatchQueue.main.asyncAfter(deadline: .now() + 2.0)delayed rechecks inrequestAccessibilityPermission()andrequestInputMonitoringPermission()withstartPermissionPolling()startPermissionPolling()call inperformStartup()after initial permission checkTesting
All 62 tests pass (
swift test). Manually verified: