Introduce named Logger interface in keeper.ts

Replaces 'ReturnType<typeof makeLogger>' with a small named interface so
simulateActivity's signature reads as (config, log: Logger) instead of a
type-derivation chain. Also makes it cleaner to substitute a mock logger
if simulateActivity is ever unit-tested.

No behavior change.
This commit is contained in:
2026-06-17 16:24:56 -05:00
parent d5656efe5b
commit 7120c06bbe
+19 -5
View File
@@ -41,11 +41,25 @@ const timestamp = (): string => {
}; };
/** /**
* Build a verbose-gated logger. `info` is unconditional; `event` only fires * Minimal log surface used by `simulateActivity` and `runKeeper`. Named so
* when the caller asked for verbose output. Returning a small object keeps * it can appear directly in function signatures (clearer than
* `simulateActivity` free of `if (verbose)` noise at every log site. * `ReturnType<typeof makeLogger>`) and so a test could substitute a fake
* implementation if needed.
*
* - `info(msg)` prints unconditionally.
* - `event(msg)` prints only when `--verbose` / `verbose: true` is set.
*/ */
function makeLogger(verbose: boolean): { info(msg: string): void; event(msg: string): void } { interface Logger {
info(msg: string): void;
event(msg: string): void;
}
/**
* Build a verbose-gated `Logger`. `info` is unconditional; `event` only
* fires when the caller asked for verbose output. Returning a small object
* keeps `simulateActivity` free of `if (verbose)` noise at every log site.
*/
function makeLogger(verbose: boolean): Logger {
return { return {
info: (msg: string): void => { info: (msg: string): void => {
console.log(msg); console.log(msg);
@@ -79,7 +93,7 @@ function makeLogger(verbose: boolean): { info(msg: string): void; event(msg: str
* so the next idle-check sees "no movement" and doesn't misread the * so the next idle-check sees "no movement" and doesn't misread the
* synthetic activity as the user returning. * synthetic activity as the user returning.
*/ */
async function simulateActivity(config: Config, log: ReturnType<typeof makeLogger>): Promise<void> { async function simulateActivity(config: Config, log: Logger): Promise<void> {
const start: Point = await mouse.getPosition(); const start: Point = await mouse.getPosition();
const screenWidth: number = await screen.width(); const screenWidth: number = await screen.width();
const screenHeight: number = await screen.height(); const screenHeight: number = await screen.height();