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:
+19
-5
@@ -41,11 +41,25 @@ const timestamp = (): string => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Minimal log surface used by `simulateActivity` and `runKeeper`. Named so
|
||||
* it can appear directly in function signatures (clearer than
|
||||
* `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 {
|
||||
info: (msg: string): void => {
|
||||
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
|
||||
* 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 screenWidth: number = await screen.width();
|
||||
const screenHeight: number = await screen.height();
|
||||
|
||||
Reference in New Issue
Block a user