mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
* docs: update contributors * fix(computer-use): 修复权限检查和应用列表获取的问题 修复 macOS 平台下权限检查的 JXA 回退逻辑,确保在没有原生模块时仍能正确检测权限 改进应用列表获取方式,使用 mdls 获取真实的 bundleId 而非生成伪 ID * docs: update contributors * docs: update contributors * docs: update contributors --------- Co-authored-by: mcjjin <8590489+mcjjin@users.noreply.github.com> Co-authored-by: claude-code-best <claude-code-best@proton.me> Co-authored-by: claude-code-best <272536312+claude-code-best@users.noreply.github.com>
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { logForDebugging } from '../debug.js'
|
|
import { releasePump, retainPump } from './drainRunLoop.js'
|
|
import { requireComputerUseSwift } from './swiftLoader.js'
|
|
|
|
/**
|
|
* Global Escape → abort. Mirrors Cowork's `escAbort.ts` but without Electron:
|
|
* CGEventTap via `@ant/computer-use-swift`. While registered, Escape is
|
|
* consumed system-wide (PI defense — a prompt-injected action can't dismiss
|
|
* a dialog with Escape).
|
|
*
|
|
* Lifecycle: register on fresh lock acquire (`wrapper.tsx` `acquireCuLock`),
|
|
* unregister on lock release (`cleanup.ts`). The tap's CFRunLoopSource sits
|
|
* in .defaultMode on CFRunLoopGetMain(), so we hold a drainRunLoop pump
|
|
* retain for the registration's lifetime — same refcounted setInterval as
|
|
* the `@MainActor` methods.
|
|
*
|
|
* `notifyExpectedEscape()` punches a hole for model-synthesized Escapes: the
|
|
* executor's `key("escape")` calls it before posting the CGEvent. Swift
|
|
* schedules a 100ms decay so a CGEvent that never reaches the tap callback
|
|
* doesn't eat the next user ESC.
|
|
*/
|
|
|
|
let registered = false
|
|
|
|
export function registerEscHotkey(onEscape: () => void): boolean {
|
|
if (process.platform !== 'darwin') return false
|
|
if (registered) return true
|
|
const cu = requireComputerUseSwift()
|
|
if (!(cu as any).hotkey?.registerEscape(onEscape)) {
|
|
// CGEvent.tapCreate failed — typically missing Accessibility permission.
|
|
// CU still works, just without ESC abort. Mirrors Cowork's escAbort.ts:81.
|
|
logForDebugging('[cu-esc] registerEscape returned false', { level: 'warn' })
|
|
return false
|
|
}
|
|
retainPump()
|
|
registered = true
|
|
logForDebugging('[cu-esc] registered')
|
|
return true
|
|
}
|
|
|
|
export function unregisterEscHotkey(): void {
|
|
if (!registered) return
|
|
try {
|
|
(requireComputerUseSwift() as any).hotkey?.unregister()
|
|
} finally {
|
|
releasePump()
|
|
registered = false
|
|
logForDebugging('[cu-esc] unregistered')
|
|
}
|
|
}
|
|
|
|
export function notifyExpectedEscape(): void {
|
|
if (!registered) return
|
|
(requireComputerUseSwift() as any).hotkey?.notifyExpectedEscape()
|
|
}
|