The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | // @effect-diagnostics globalTimers:off -- A plain Node child; the poll runs outside any Effect fiber. |
| 2 | import { SNAP_SHOT_MODIFIERS, type SnapShotModifier } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { loadWindowsForegroundApi } from "../electron/WindowsForeground.ts"; |
| 5 | import { WINDOWS_MODIFIER_PAIR_VIRTUAL_KEYS } from "./snapShot.ts"; |
| 6 | |
| 7 | const POLL_INTERVAL_MS = 50; |
| 8 | |
| 9 | const requested = process.argv[2]; |
| 10 | if (!(SNAP_SHOT_MODIFIERS as readonly string[]).includes(requested ?? "")) { |
| 11 | process.exit(1); |
| 12 | } |
| 13 | const [left, right] = WINDOWS_MODIFIER_PAIR_VIRTUAL_KEYS[requested as SnapShotModifier]; |
| 14 | |
| 15 | async function poll() { |
| 16 | const api = await loadWindowsForegroundApi(); |
| 17 | let active = false; |
| 18 | process.send?.("ready"); |
| 19 | const timer = setInterval(() => { |
| 20 | const pressed = api.isKeyDown(left) && api.isKeyDown(right); |
| 21 | if (pressed && !active) { |
| 22 | try { |
| 23 | process.send?.("trigger"); |
| 24 | } catch {} |
| 25 | } |
| 26 | active = pressed; |
| 27 | }, POLL_INTERVAL_MS); |
| 28 | const shutdown = () => { |
| 29 | clearInterval(timer); |
| 30 | process.exit(0); |
| 31 | }; |
| 32 | process.once("disconnect", shutdown); |
| 33 | process.once("SIGTERM", shutdown); |
| 34 | } |
| 35 | |
| 36 | void poll().catch(() => process.exit(1)); |