fix(control): release buttons on quit & settle clicks before pressing - #49
Merged
Conversation
Two bugs, both causing the host to be unable to click after a remote-control session — in the worst case requiring a reboot. **On quit, the OS-level release never ran.** `will-quit` fired `dispose()` via `void`, so Electron tore down the process before the async cleanup finished. Even if it had completed, `dispose()` → `releaseAll()` only released buttons in `heldButtons` and exited immediately when the set was empty — a press that had ever escaped tracking stayed down for the whole OS session. Fixed: `will-quit` now blocks quit with preventDefault(), runs disposal with a 2-second deadline, and terminates via app.exit(). `dispose()` always calls `backend.emergencyStop()` which releases LEFT/RIGHT/MIDDLE unconditionally. **disable() ran releaseAll without emergencyStop.** Taking back control released tracked buttons only, so the host regaining control still had a stuck mouse if the tracking had a gap. `emergencyStop` now follows `releaseAll` on every disable, and releasing a button that is not pressed is a harmless no-op. **Clicks could land before the pointer arrived.** nut-js was configured with autoDelayMs = 0, so a position change and button event were delivered back-to-back. macOS applies the synthetic move asynchronously, so the press could be delivered before the pointer had moved — the click landed wherever the pointer used to be. A one-frame settle before each button action lets the window server catch up. The restore after a click also benefits: without a gap the whole cycle is a sub-millisecond blip that many controls ignore outright.
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 was referenced Aug 10, 2026
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 1: Host needs a reboot after remote control
will-quitfireddispose()viavoid— never awaited, Electron tore downthe process before the async cleanup finished. Even when it completed, it
only released buttons in
heldButtonsand exited immediately when the setwas empty. A press that ever escaped tracking stayed down at the OS level
for the whole session.
Fix:
will-quitnow blocks quit withpreventDefault(), runs disposalwith a 2-second deadline, and terminates via
app.exit().dispose()alwayscalls
backend.emergencyStop()which releases L/R/M unconditionally.Bug 2: Guest can move but can't click
nut-jswas configured withautoDelayMs = 0, so the pointer move andbutton press were delivered back-to-back. macOS applies the synthetic move
asynchronously, so the press could be delivered before the pointer had
moved — the click lands wherever the pointer used to be.
Fix: A one-frame (16ms) settle before every button action lets the
window server catch up. Also makes the press-release gap long enough for
target apps to register it as a real click instead of a sub-millisecond blip.
Bug 3: disable() didn't call emergencyStop
Taking back control released tracked buttons only (
releaseAll). If trackinghad a gap, the host regaining control still had a stuck mouse.
emergencyStop(which unconditionally releases all mouse buttons) now runs after every
disable(). Releasing an unpressed button is a harmless no-op.Validation: lint, typecheck, 1451 tests, 34 script tests, format, build — all green.