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:
1 parent
fc7a54b40a
commit
bb873807b8
2 files changed
+22
-3
No files matched your search
@@ -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
|
||||
|
||||
@@ -392,7 +392,12 @@ Rules the consuming lanes must honour:
|
||||
jerked the pointer to the top of the screen whenever `.tapLost` or a
|
||||
revoked grant fired while control was already local. `nil` means
|
||||
"show and re-associate, do not move", and it is idempotent.
|
||||
6. **`DispatchSourceSignal`, not `signal(2)`.** A C signal handler may
|
||||
6. **The permission health check installs the tap, not just reports it.**
|
||||
The 5 s check already had to notice a *revoked* grant (C2); noticing
|
||||
the grant arriving and retrying `EventTap.start()` costs four lines
|
||||
and means the user does not have to restart the app after ticking
|
||||
the box in System Settings.
|
||||
7. **`DispatchSourceSignal`, not `signal(2)`.** A C signal handler may
|
||||
only call async-signal-safe functions, and the emergency release
|
||||
does `queue.sync` and posts `CGEvent`s. A dispatch signal source
|
||||
runs the same code on an ordinary queue, which is both safe and
|
||||
|
||||
Reference in new issue
Block a user