πŸ“„ File detail

utils/modifiers.ts

🧩 .tsπŸ“ 37 linesπŸ’Ύ 1,112 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes ModifierKey, prewarmModifiers, and isModifierPressed β€” mainly functions, hooks, or classes.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

export type ModifierKey = 'shift' | 'command' | 'control' | 'option' let prewarmed = false /**

πŸ“€ Exports (heuristic)

  • ModifierKey
  • prewarmModifiers
  • isModifierPressed

πŸ–₯️ Source preview

export type ModifierKey = 'shift' | 'command' | 'control' | 'option'

let prewarmed = false

/**
 * Pre-warm the native module by loading it in advance.
 * Call this early to avoid delay on first use.
 */
export function prewarmModifiers(): void {
  if (prewarmed || process.platform !== 'darwin') {
    return
  }
  prewarmed = true
  // Load module in background
  try {
    // eslint-disable-next-line @typescript-eslint/no-require-imports
    const { prewarm } = require('modifiers-napi') as { prewarm: () => void }
    prewarm()
  } catch {
    // Ignore errors during prewarm
  }
}

/**
 * Check if a specific modifier key is currently pressed (synchronous).
 */
export function isModifierPressed(modifier: ModifierKey): boolean {
  if (process.platform !== 'darwin') {
    return false
  }
  // Dynamic import to avoid loading native module at top level
  const { isModifierPressed: nativeIsModifierPressed } =
    // eslint-disable-next-line @typescript-eslint/no-require-imports
    require('modifiers-napi') as { isModifierPressed: (m: string) => boolean }
  return nativeIsModifierPressed(modifier)
}