mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-05-09 15:48:04 +03:00
macos: quit immediately when Accessibility is revoked mid-session
Even with the earlier event-tap-callback cleanup fix, revoking Accessibility in System Settings while Lan Mouse was running with an active capture tap could still leave system input wedged — clicks and keypresses silently dropped until the app was force-quit. The reliable fix is to not rely on in-process tap teardown at all. When AX is revoked: - The kernel guarantees an active CGEventTap is dismantled when the owning process exits. - SIGINT+wait on the daemon child (main.rs already does this on GUI exit) drops the daemon's tap and restores the cursor. So: continuously poll AX state (1-second GLib timer, replacing the one-shot grant watcher), and on a revoke transition call `app.quit()`. Input is restored within ~1-2 seconds regardless of capture state — no force-quit required, no stuck cursor, no silently consumed events beyond the brief window until the poller fires. The grant-transition case is preserved: on a 0→1 flip the warning row swaps to its "relaunch required" state, same as before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Ferdinand Schober
parent
07cc40f6ba
commit
94e9301e9c
@@ -200,17 +200,31 @@ fn build_ui(app: &Application) {
|
||||
macos_status_item::setup(app, &window);
|
||||
// First-launch TCC prompts. No-op when already granted.
|
||||
macos_privacy::fire_initial_prompts();
|
||||
// If Accessibility wasn't granted at startup, watch for the grant
|
||||
// and switch the status row into its "relaunch required" state
|
||||
// when it lands. The daemon subprocess initialized without AX
|
||||
// (bailed with "accessibility permission is required") and can't
|
||||
// recover without a restart, so a live AX toggle without a
|
||||
// relaunch leaves the app in a broken state otherwise.
|
||||
// Watch the Accessibility grant continuously for the lifetime
|
||||
// of the process. On a grant, swap the warning row into its
|
||||
// "relaunch required" state (the daemon subprocess already
|
||||
// bailed and can't recover without a restart). On a REVOKE,
|
||||
// quit immediately — an active CGEventTap at
|
||||
// HeadInsertEventTap can wedge system input if the process
|
||||
// lingers after losing AX, and forcing the process to exit is
|
||||
// the only bulletproof way to guarantee the kernel tears the
|
||||
// tap down.
|
||||
let window_weak = window.downgrade();
|
||||
macos_privacy::watch_for_accessibility_grant(move || {
|
||||
if let Some(window) = window_weak.upgrade() {
|
||||
window.present();
|
||||
window.refresh_capture_emulation_status();
|
||||
let app_weak = app.downgrade();
|
||||
macos_privacy::watch_accessibility_state(move |change| match change {
|
||||
macos_privacy::AccessibilityChange::Granted => {
|
||||
if let Some(window) = window_weak.upgrade() {
|
||||
window.present();
|
||||
window.refresh_capture_emulation_status();
|
||||
}
|
||||
}
|
||||
macos_privacy::AccessibilityChange::Revoked => {
|
||||
log::warn!(
|
||||
"Accessibility revoked — quitting to avoid wedging system input"
|
||||
);
|
||||
if let Some(app) = app_weak.upgrade() {
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user