同步操作将从 ZeroFreeze/claude-code-source-code 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import { logForDebugging } from '../debug.js'import { withResolvers } from '../withResolvers.js'import { requireComputerUseSwift } from './swiftLoader.js'/*** Shared CFRunLoop pump. Swift's four `@MainActor` async methods* (captureExcluding, captureRegion, apps.listInstalled, resolvePrepareCapture)* and `@ant/computer-use-input`'s key()/keys() all dispatch to* DispatchQueue.main. Under libuv (Node/bun) that queue never drains — the* promises hang. Electron drains it via CFRunLoop so Cowork doesn't need this.** One refcounted setInterval calls `_drainMainRunLoop` (RunLoop.main.run)* every 1ms while any main-queue-dependent call is pending. Multiple* concurrent drainRunLoop() calls share the single pump via retain/release.*/let pump: ReturnType<typeof setInterval> | undefinedlet pending = 0function drainTick(cu: ReturnType<typeof requireComputerUseSwift>): void {cu._drainMainRunLoop()}function retain(): void {pending++if (pump === undefined) {pump = setInterval(drainTick, 1, requireComputerUseSwift())logForDebugging('[drainRunLoop] pump started', { level: 'verbose' })}}function release(): void {pending--if (pending <= 0 && pump !== undefined) {clearInterval(pump)pump = undefinedlogForDebugging('[drainRunLoop] pump stopped', { level: 'verbose' })pending = 0}}const TIMEOUT_MS = 30_000function timeoutReject(reject: (e: Error) => void): void {reject(new Error(`computer-use native call exceeded ${TIMEOUT_MS}ms`))}/*** Hold a pump reference for the lifetime of a long-lived registration* (e.g. the CGEventTap Escape handler). Unlike `drainRunLoop(fn)` this has* no timeout — the caller is responsible for calling `releasePump()`. Same* refcount as drainRunLoop calls, so nesting is safe.*/export const retainPump = retainexport const releasePump = release/*** Await `fn()` with the shared drain pump running. Safe to nest — multiple* concurrent drainRunLoop() calls share one setInterval.*/export async function drainRunLoop<T>(fn: () => Promise<T>): Promise<T> {retain()let timer: ReturnType<typeof setTimeout> | undefinedtry {// If the timeout wins the race, fn()'s promise is orphaned — a late// rejection from the native layer would become an unhandledRejection.// Attaching a no-op catch swallows it; the timeout error is what surfaces.// fn() sits inside try so a synchronous throw (e.g. NAPI argument// validation) still reaches release() — otherwise the pump leaks.const work = fn()work.catch(() => {})const timeout = withResolvers<never>()timer = setTimeout(timeoutReject, TIMEOUT_MS, timeout.reject)return await Promise.race([work, timeout.promise])} finally {clearTimeout(timer)release()}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。