Repository navigation
Description
Problem
When installed via TestFlight, AXIsProcessTrustedWithOptions returns false even though the app is enabled in System Settings > Privacy & Security > Accessibility. Toggling the permission doesn't resolve it. The app runs in a container path (Library/Containers/com.inputmetrics.InputMetrics/).
Logs on startup:
Database path: ~/Library/Containers/com.inputmetrics.InputMetrics/Data/Library/Application Support/InputMetrics/metrics.db
Database initialized successfully
InputMetrics launched successfully
⚠️ Accessibility permission not granted
📋 Please enable InputMetrics in System Settings > Privacy & Security > Accessibility
Root Cause
AXIsProcessTrustedWithOptions queries the TCC database for the exact executable path. TestFlight/App Store builds run from a different path than dev builds, and the sandbox container changes the process identity. The TCC entry may not match what the runtime resolves.
Proposed Fix
File: InputMetrics/InputMetrics/Services/EventMonitor.swift
-
Remove the
AXIsProcessTrustedWithOptionsgate. Instead, attemptCGEvent.tapCreate(...)directly — if it returnsnil, permission is denied. This tests the actual capability rather than querying TCC. -
Add polling retry. After showing the permission alert, poll every 2 seconds (up to 30 attempts) trying to create the event tap. Once it succeeds, start monitoring — no app restart needed.
-
Keep the alert/prompt directing the user to System Settings on initial failure.
Updated start() flow:
start()
├─ try CGEvent.tapCreate(...)
├─ success → wire up run loop, done
└─ nil (denied) →
├─ show NSAlert with "Open System Settings" button
└─ start polling timer (every 2s, up to 30 attempts)
└─ each tick: try CGEvent.tapCreate(...)
├─ success → wire up run loop, cancel timer
└─ nil → continue polling
Changes:
- Remove
checkAccessibilityPermission()andrequestAccessibilityPermission()methods - Extract tap creation + run loop wiring into
private func createAndStartEventTap() -> Bool - Add a
Timerthat retries every 2s, cancel on success or after 30 attempts
Verification
- Build and archive with Release config
- Install via TestFlight
- Grant Accessibility permission when prompted
- Confirm "Event monitoring started" appears without restarting the app
Activity