app-engine: install the event tap when the permission finally arrives

The 5 s health check already had to notice Input Monitoring being
revoked (contracts C2). Noticing it being granted and retrying
EventTap.start() means a first run does not have to be restarted after
the user ticks the box in System Settings.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 03:36:21 -07:00
1 parent fc7a54b40a
commit bb873807b8
2 files changed
+22 -3

No files matched your search

+16 -2
View File
@@ -274,14 +274,28 @@ extension Engine {
}
/// The 5 s health check noticed a grant change (contracts C2).
///
/// Losing Input Monitoring means the tap is dead, so control comes home.
/// *Gaining* it is the other half: the tap that could not be installed at
/// startup is retried here, so granting the permission does not need a
/// restart. `EventTap.start()` is a no-op when one is already running.
func notePermissions(_ state: PermissionState) {
let lostListening = permissions.listen && !state.listen
permissions = state
if lostListening {
recoverLocal(reason: .permissionsLost)
} else {
publish()
return
}
if state.isComplete, let tap, !tap.isRunning {
do {
try tap.start()
tap.reconfigure(captureConfig())
Log.app.info("permissions granted; event tap installed")
} catch {
Log.app.error("event tap still not installable: \(error)")
}
}
publish()
}
// MARK: - Persistence