From ccce39a83af422a9fc335a277bb8257971e66111 Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Sat, 11 Jul 2026 22:44:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20=E6=96=87=E5=AD=97=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E5=B4=A9=E6=BA=83=E2=80=94=E2=80=94=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E9=94=AE=E7=94=A8=E7=89=A9=E7=90=86=E9=94=AE=E7=A0=81=E9=81=BF?= =?UTF-8?q?=E5=BC=80=E4=B8=BB=E7=BA=BF=E7=A8=8B=E9=99=90=E5=88=B6=E7=9A=84?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enigo 的 Key::Unicode('v') 会调 TSMGetInputSourceProperty 查键盘布局,该 API 必须主线程执行;注入跑在 tokio 后台线程上,macOS 15/26 收紧主线程校验后触发断言崩溃(松开说话、识别成功后注入即崩)。改用 kVK_ANSI_V 物理键码 Key::Other(9),走 CGEvent 无需布局查询,与键盘布局无关。 Co-Authored-By: Claude Fable 5 --- desktop/src-tauri/src/inject.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/desktop/src-tauri/src/inject.rs b/desktop/src-tauri/src/inject.rs index b592c34..9fcf450 100644 --- a/desktop/src-tauri/src/inject.rs +++ b/desktop/src-tauri/src/inject.rs @@ -57,10 +57,18 @@ pub fn inject_text(text: &str) -> Result<(), String> { #[cfg(not(target_os = "macos"))] let modifier = Key::Control; + // 粘贴键 V: + // macOS 用物理键码 9(kVK_ANSI_V),直接走 CGEvent,避开 enigo 对 + // Key::Unicode 的键盘布局查询——那条路径调 TSMGetInputSourceProperty, + // 该 API 必须在主线程执行,在 tokio 后台线程上调用会触发断言崩溃 + // (macOS 15/26 收紧了主线程校验)。物理键码与布局无关,粘贴恒为此键位。 + #[cfg(target_os = "macos")] + let paste_key = Key::Other(9); + #[cfg(not(target_os = "macos"))] + let paste_key = Key::Unicode('v'); + enigo.key(modifier, Direction::Press).map_err(|e| e.to_string())?; - enigo - .key(Key::Unicode('v'), Direction::Click) - .map_err(|e| e.to_string())?; + enigo.key(paste_key, Direction::Click).map_err(|e| e.to_string())?; enigo .key(modifier, Direction::Release) .map_err(|e| e.to_string())?;