From 332224c923c131d02253e40bbbaca3bd8826d439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=9F=8F=E9=9D=92?= Date: Mon, 15 Jun 2026 22:12:46 +0800 Subject: [PATCH] =?UTF-8?q?perf(coordinator):=20=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E7=83=AD=E9=94=AE=20supervisor=20=E6=B3=A8=E5=86=8C=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=8D=B3=E9=80=80=E5=87=BA=EF=BC=8C=E5=BD=BB=E5=BA=95?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E7=A8=B3=E6=80=81=E8=BD=AE=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue #470:combo/translation/action 三类可选热键 supervisor 原本注册成功后不退出,稳态 每 5s 醒来读 prefs,多线程常驻空转。改为对齐主 hotkey_supervisor_loop 的 exit-on-success 模式——到达「已安装」或「已主动停用」稳态即 return 退出,零轮询。 安全前提(已逐函数确认):用户启用/改/停这些热键时,set_*_hotkey 命令与 persist_settings diff 都会调 update_*_hotkey_binding,其覆盖「monitor 为 None → 从零 start+spawn」安装路径, 故退出后启停改键无需重启即时生效;ComboHotkeyMonitor 注册后驻留、无运行中自注销,monitor 不会自己死,无需 supervisor 守护。失败重试 sleep(3s)/recv_timeout(5s)/app未就绪 sleep(1s) 等有界路径全部保留。 --- openless-all/app/src-tauri/src/coordinator.rs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/openless-all/app/src-tauri/src/coordinator.rs b/openless-all/app/src-tauri/src/coordinator.rs index 85e3787f..dcdbd5a2 100644 --- a/openless-all/app/src-tauri/src/coordinator.rs +++ b/openless-all/app/src-tauri/src/coordinator.rs @@ -2142,22 +2142,22 @@ fn combo_hotkey_supervisor_loop(inner: Arc) { // 读当前 prefs let prefs = inner.prefs.get(); if crate::shortcut_binding::legacy_modifier_trigger(&prefs.dictation_hotkey).is_some() { - // 不是 Custom → 睡着等 prefs 改动 + // 不是 Custom → 卸载后退出守护 take_combo_hotkey_on_main_thread(&inner); - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470 + return; } let binding = prefs.dictation_hotkey.clone(); if is_unconfigured_shortcut(&binding) { take_combo_hotkey_on_main_thread(&inner); - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470 + return; } if inner.combo_hotkey.lock().is_some() { - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470 + return; } let app = inner.app.lock().clone(); @@ -2255,13 +2255,13 @@ fn translation_hotkey_supervisor_loop(inner: Arc) { let (qa_trigger, translation_trigger) = modifier_shortcut_triggers(&inner); monitor.update_modifier_shortcuts(qa_trigger, translation_trigger); } - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 try_update_translation_hotkey_binding 主动路径,issue #470 + return; } if inner.translation_hotkey.lock().is_some() { - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 try_update_translation_hotkey_binding 主动路径,issue #470 + return; } let app = match inner.app.lock().clone() { @@ -2348,21 +2348,21 @@ fn action_hotkey_supervisor_loop(inner: Arc, kind: ActionHotkeyKind) { if inner.shutdown.load(Ordering::SeqCst) { return; } - // None = 用户主动停用:反注册并睡着等 prefs 改动(由 update 路径唤醒)。 + // None = 用户主动停用:反注册后退出守护(由 update_action_hotkey_binding 主动路径重装)。 let Some(binding) = action_hotkey_binding(&inner, kind) else { take_action_hotkey_on_main_thread(&inner, kind); - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470 + return; }; if is_modifier_only_shortcut(&binding) { take_action_hotkey_on_main_thread(&inner, kind); - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470 + return; } if action_hotkey_slot(&inner, kind).lock().is_some() { - std::thread::sleep(std::time::Duration::from_secs(5)); - continue; + // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470 + return; } let app = match inner.app.lock().clone() {