markInputQuietSchedulerInput (lib/input-quiet-scheduler.ts)

orca · src/renderer/src/lib/input-quiet-scheduler.ts · typescript · MIT
automation, tag:knn-classified

Schedules callbacks after a quiet period of user input, improving UI responsiveness by deferring heavy work.

// Source: https://github.com/stablyai/orca | License: MIT | Copyright 2026 Lovecast Inc
// Provided via justclaw.it.com; keep this notice with the code.
type InputQuietScheduleOptions = {
  delayMs: number
  quietMs: number
  idleTimeoutMs: number
  maxWaitMs?: number
}

const INPUT_QUIET_EVENTS: readonly (keyof WindowEventMap)[] = [
  'keydown',
  'pointerdown',
  'pointermove',
  'pointerup',
  'touchstart',
  'wheel'
]

let listenersInstalled = false
let listenersWindow: Window | null = null
let lastInputAt = Number.NEGATIVE_INFINITY

function now(): number {
  return typeof performance !== 'undefined' ? performance.now() : Date.now()
}

function recordInput(): void {
  lastInputAt = now()
}

export function markInputQuietSchedulerInput(): void {
  recordInput()
}

export function rese

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key