fix(control): serialize inject/disable to prevent permanently stuck clicks - #48
Merged
Merged
Conversation
…licks
When inject('down') was in-flight (mid-await inside dispatch), disable()
released nothing because trackHeldState hadn't added the button to heldButtons
yet. Nut.js had already pressed it at the OS level, so the release never came.
Every subsequent click was then treated as a continuation of that drag — hence
"neither side can click anything."
Inject now chains onto a promise so disable() and emergencyStop() wait for any
in-progress injection to finish before reading heldButtons — releaseAll always
sees the post-trackHeldState state.
Also adds pointer event listeners so trackpads that fire pointer events without
mouse events still produce clicks on the host. A dedup ref prevents the
mouse-event double-fire Chromium also delivers.
ThreatCrush Security Scan160 finding(s) HIGH/CRITICAL: 5 | MEDIUM: 49 | LOW: 106
…and 110 more. Full results in the Security tab. Snippets are redacted; ThreatCrush never prints matched credential material. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Neither the host nor the guest could click anything during remote control.
Root cause
A race between
inject('down')anddisable(). When the guest pressed abutton:
inject('down')→dispatch()→await getCursorPosition()(yields event loop)disable()→releaseAll()releaseAllreadheldButtons— which was empty becausetrackHeldStatehadn't run yetdispatchresumed → nut-js pressed the button at the OS leveltrackHeldStaterecorded{'left'}in heldButtons — too lateThe OS-level button press went through but the release never came. Every
subsequent click was treated as a continuation of that drag, so nothing was
clickable — for either person — until the process was restarted.
Fix
inject()now chains onto apendingInjectpromise.disable()andemergencyStop()wait for any in-progress injection to finish before callingreleaseAll(), so heldButtons always reflects the post-trackHeldState state.Also
Added pointer event listeners (
pointerdown/pointerup/pointermove)alongside the existing mouse event listeners, with a 100ms dedup window so
Chromium's double-fire (pointer then mouse) only results in one event. This
covers trackpads that emit pointer events without mouse events.
Validation: lint, typecheck, 1447 tests, 34 script tests, format, build — all green.