Files
claude-code/src/utils/modifiers.ts
unraid fb41513b32 feat: 添加工具类增强与状态管理改进
- 新增 workflowRuns、remoteTriggerAudit、pipeStatus 等工具
- 增强 permissionSetup: auto mode 和 bypass permissions 始终可用
- 新增多组测试覆盖 (modifiers, teamDiscovery, deepLink 等)
- 修复 parseInt 缺少 radix 参数
- 移除多余 biome-ignore 注释

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-22 22:38:10 +08:00

33 lines
924 B
TypeScript

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
void import('modifiers-napi').then(({ prewarm }) => prewarm()).catch(() => {})
}
/**
* Check if a specific modifier key is currently pressed (synchronous).
*/
export function isModifierPressed(modifier: ModifierKey): boolean {
if (process.platform !== 'darwin') {
return false
}
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { isModifierPressed: nativeIsModifierPressed } =
require('modifiers-napi') as { isModifierPressed: (m: string) => boolean }
return nativeIsModifierPressed(modifier)
} catch {
return false
}
}