diff --git a/Sources/mwb/EngineActions.swift b/Sources/mwb/EngineActions.swift index 5268287..c04d42d 100644 --- a/Sources/mwb/EngineActions.swift +++ b/Sources/mwb/EngineActions.swift @@ -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 diff --git a/docs/features/app-engine/README.md b/docs/features/app-engine/README.md index eb7b4f9..c6bcd6e 100644 --- a/docs/features/app-engine/README.md +++ b/docs/features/app-engine/README.md @@ -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