From d5656efe5b1d5455db05ec02a44e7496fba15cb1 Mon Sep 17 00:00:00 2001 From: nokeo08 Date: Wed, 17 Jun 2026 16:24:24 -0500 Subject: [PATCH] Move 'mouse.config.autoDelayMs = 0' from module-load to runKeeper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assignment used to run at import time, mutating the shared nut.js singleton the second anything imported keeper.ts. Moved into the top of runKeeper(), where the only caller actually needs it. Same observable behavior — runKeeper is called exactly once per process — but keeper.ts is now import-side-effect-free, which makes it straightforward to import for tests or future tooling without touching global mouse state. --- src/keeper.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/keeper.ts b/src/keeper.ts index f97252c..540d6aa 100644 --- a/src/keeper.ts +++ b/src/keeper.ts @@ -5,8 +5,8 @@ * real-user-wins semantics, plus the idle-watch loop that drives it. * * Runtime: Bun (uses `@nut-tree-fork/nut-js` for cross-platform mouse + - * screen). Importing this module sets `mouse.config.autoDelayMs = 0` as a - * side effect — see below. + * screen). The nut.js auto-delay is disabled inside `runKeeper`, not at + * module load, so importing this module is side-effect-free. * * Logging policy: * - The startup banner in `runKeeper` is unconditional so the user always @@ -20,14 +20,6 @@ import { mouse, Point, screen } from "@nut-tree-fork/nut-js"; import type { Config } from "./config.ts"; -/** - * nut.js inserts a configurable delay after every action (default 100ms). - * That default would silently more-than-double the duration of every - * `setPosition` and `getPosition` call. We drive cadence ourselves via - * `Config.stepDelay`, so disable nut.js's implicit delay entirely. - */ -mouse.config.autoDelayMs = 0; - /** * Promise-based `setTimeout` wrapper. Allows `await sleep(ms)` ergonomics. * @@ -145,6 +137,17 @@ async function simulateActivity(config: Config, log: ReturnType { + // nut.js inserts a configurable delay after every action (default 100ms). + // That default would silently more-than-double the duration of every + // setPosition and getPosition call. We drive cadence ourselves via + // config.stepDelay, so disable nut.js's implicit delay entirely. + // + // Setting this here (rather than at module load) keeps `keeper.ts` free + // of import-time side effects on the shared nut.js singleton — useful + // for tests and any future code path that imports this module without + // actually running the loop. + mouse.config.autoDelayMs = 0; + const log = makeLogger(config.verbose); log.info("Teams Status Keeper started. Press Ctrl+C to stop.");