From 6b88844d1bf8727deb1716bd32fe161779bd0f91 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 2 Oct 2026 19:32:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=82=B9=E5=87=BB=E5=A4=AA=E7=81=B5?= =?UTF-8?q?=E6=95=8F=20=E2=80=94=20opaque=20app=20nudgeAX=20sleep=20?= =?UTF-8?q?=E6=9C=9F=E9=97=B4=E6=A3=80=E6=B5=8B=E6=9D=BE=E6=89=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `.press + 350ms` 进入激活分支时,AX-opaque app 会 nudgeAX(pid) + usleep(250ms)。阻塞期间用户可能已松手, 原代码 sleep 后继续推进到 .recording,导致"点击就出来"。 修法:usleep 后再查 buttonState,已松开 → .dead + cancel, break 出 .press 分支,不再升级成录音。 Co-Authored-By: Claude Opus 5.5 (1M context) --- src/voicetype.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/voicetype.swift b/src/voicetype.swift index a7fd2d1..791700d 100644 --- a/src/voicetype.swift +++ b/src/voicetype.swift @@ -812,6 +812,13 @@ Thread.detachNewThread { var role = focusedTextRole(pid: pid) if role == nil { nudgeAX(pid); usleep(250_000) + // 250ms 阻塞期间用户可能已松手;再查 buttonState, + // 已松开 → 立刻 .dead,不把"已结束的点击"升级成录音 + if !CGEventSource.buttonState(.combinedSessionState, button: .left) { + state.v = .dead + DispatchQueue.global().async { Engine.current.cancel() } + break // 跳出 switch 的 .press 分支,回到 polling 顶 + } role = focusedTextRole(pid: pid) } func startRec() {