Skip to content

fix: auto-detect accessibility permission changes without restart - #64

Merged
jatinkrmalik merged 1 commit into
mainfrom
fix/accessibility-permission-polling
Mar 12, 2026
Merged

fix: auto-detect accessibility permission changes without restart#64
jatinkrmalik merged 1 commit into
mainfrom
fix/accessibility-permission-polling

Conversation

@jatinkrmalik

Copy link
Copy Markdown
Member

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:

  • Restarted the app, or
  • Clicked "Recheck Permissions" in Settings

Microphone permission worked instantly (callback-based API), but Accessibility and Input Monitoring use AXIsProcessTrustedWithOptions and CGEvent.tapCreate respectively — 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

  • Starts automatically on app launch if any permission is missing
  • Starts on demand when the user clicks a permission request button (which opens System Settings)
  • Polls every 3 seconds — calls checkPermissions() to refresh all three permission states
  • Auto-starts the hotkey listener when Accessibility + Input Monitoring are both granted mid-session (so the user doesn't need to restart)
  • Stops itself once all permissions are granted — no wasted CPU cycles during normal operation

Changes (AppState.swift)

  • Added permissionPollTimer property
  • Added startPermissionPolling() — creates a 3-second repeating timer, guarded against duplicate starts and skipped if all permissions are already granted
  • Added stopPermissionPolling() — invalidates and nils the timer
  • Added allPermissionsGranted computed property for clean stop condition
  • Replaced one-shot DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) delayed rechecks in requestAccessibilityPermission() and requestInputMonitoringPermission() with startPermissionPolling()
  • Added startPermissionPolling() call in performStartup() after initial permission check

Testing

All 62 tests pass (swift test). Manually verified:

  • Grant Accessibility in System Settings → popover updates within ~3 seconds
  • Grant Input Monitoring → same behavior
  • Polling stops automatically once all permissions are granted
  • Hotkey listener auto-starts after permissions are granted (no restart needed)

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
@jatinkrmalik
jatinkrmalik merged commit 0e18c08 into main Mar 12, 2026
1 check passed
@jatinkrmalik
jatinkrmalik deleted the fix/accessibility-permission-polling branch August 22, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant