Skip to content

feat: lastInputMs answers the session's idle time from CGEventSource, synchronously on any thread, so react-x11's useIdle reads it from the bridge where it shelled out to ioreg for HIDIdleTime - #122

Merged
sidorares merged 2 commits into
mainfrom
claude/react-x11-bridge-followup-ead6ed
Oct 12, 2026

Conversation

@sidorares

@sidorares sidorares commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The bridge follow-up from sidorares/react-x11#951. useIdle on macOS now uses native.lastInputMs() when the bridge has it, and shells out to ioreg … HIDIdleTime (a child per poll) otherwise. With this shipped, react-x11 needs no JS change.

native.lastInputMs(): number: milliseconds since the last keyboard, mouse, trackpad or tablet event in the login session, from any app. It is CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType) * 1000.

  • It needs no permission and makes no AppKit call. It answers synchronously on the calling thread: before initApp, in pump mode, and from a worker with the main thread in runMain. It's listed in the README's "unchanged, on the calling thread" row.
  • It is not ioreg's HIDIdleTime. The two are kept separately: they agree at a desk, but on CI's VMs lastInputMs ran 3–5 s longer.

Test: test/last-input.js is in npm test and CI. A test can't make or withhold the user's input, so it checks only what holds either way:

  • Before initApp, it returns a finite number ≥ 0.
  • Across two reads 300 ms apart, it either grew by the time between them or was reset by input.
  • It logs HIDIdleTime beside lastInputMs for comparison, without asserting anything about the two.
  • From a worker, with the main thread parked in runMain, it returns a number synchronously.

Docs: a README section "Idle time (an empty desk)".

… synchronously on any thread, so react-x11's useIdle reads it from the bridge where it shelled out to ioreg for HIDIdleTime (sidorares/react-x11#951)
…ding one by the other, since on CI's VMs lastInputMs ran 3-5 s longer
@sidorares
sidorares merged commit 3047bf0 into main Oct 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant