perf(coordinator): 可选热键 supervisor 注册成功即退出,彻底消除稳态轮询 (#671)

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)
等有界路径全部保留。

Co-authored-by: 吕柏青 <lubaiqing9@gmail.com>
This commit is contained in:
TRIPand吕柏青 authored and GitHub committed 2026-06-16 10:56:37 +08:00
1 parent 16e0f27685
commit 2d783ce337
1 file changed
+18 -18
+18 -18
View File
@@ -2142,22 +2142,22 @@ fn combo_hotkey_supervisor_loop(inner: Arc<Inner>) {
// 读当前 prefs // 读当前 prefs
let prefs = inner.prefs.get(); let prefs = inner.prefs.get();
if crate::shortcut_binding::legacy_modifier_trigger(&prefs.dictation_hotkey).is_some() { if crate::shortcut_binding::legacy_modifier_trigger(&prefs.dictation_hotkey).is_some() {
// 不是 Custom → 睡着等 prefs 改动 // 不是 Custom → 卸载后退出守护
take_combo_hotkey_on_main_thread(&inner); take_combo_hotkey_on_main_thread(&inner);
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470
continue; return;
} }
let binding = prefs.dictation_hotkey.clone(); let binding = prefs.dictation_hotkey.clone();
if is_unconfigured_shortcut(&binding) { if is_unconfigured_shortcut(&binding) {
take_combo_hotkey_on_main_thread(&inner); take_combo_hotkey_on_main_thread(&inner);
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470
continue; return;
} }
if inner.combo_hotkey.lock().is_some() { if inner.combo_hotkey.lock().is_some() {
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_combo_hotkey_binding 主动路径,issue #470
continue; return;
} }
let app = inner.app.lock().clone(); let app = inner.app.lock().clone();
@@ -2255,13 +2255,13 @@ fn translation_hotkey_supervisor_loop(inner: Arc<Inner>) {
let (qa_trigger, translation_trigger) = modifier_shortcut_triggers(&inner); let (qa_trigger, translation_trigger) = modifier_shortcut_triggers(&inner);
monitor.update_modifier_shortcuts(qa_trigger, translation_trigger); monitor.update_modifier_shortcuts(qa_trigger, translation_trigger);
} }
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 try_update_translation_hotkey_binding 主动路径,issue #470
continue; return;
} }
if inner.translation_hotkey.lock().is_some() { if inner.translation_hotkey.lock().is_some() {
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 try_update_translation_hotkey_binding 主动路径,issue #470
continue; return;
} }
let app = match inner.app.lock().clone() { let app = match inner.app.lock().clone() {
@@ -2348,21 +2348,21 @@ fn action_hotkey_supervisor_loop(inner: Arc<Inner>, kind: ActionHotkeyKind) {
if inner.shutdown.load(Ordering::SeqCst) { if inner.shutdown.load(Ordering::SeqCst) {
return; return;
} }
// None = 用户主动停用:反注册并睡着等 prefs 改动(由 update 路径唤醒)。 // None = 用户主动停用:反注册后退出守护(由 update_action_hotkey_binding 主动路径重装)。
let Some(binding) = action_hotkey_binding(&inner, kind) else { let Some(binding) = action_hotkey_binding(&inner, kind) else {
take_action_hotkey_on_main_thread(&inner, kind); take_action_hotkey_on_main_thread(&inner, kind);
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470
continue; return;
}; };
if is_modifier_only_shortcut(&binding) { if is_modifier_only_shortcut(&binding) {
take_action_hotkey_on_main_thread(&inner, kind); take_action_hotkey_on_main_thread(&inner, kind);
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470
continue; return;
} }
if action_hotkey_slot(&inner, kind).lock().is_some() { if action_hotkey_slot(&inner, kind).lock().is_some() {
std::thread::sleep(std::time::Duration::from_secs(5)); // 对齐主 supervisor 的 exit-on-success:装/卸交给 update_action_hotkey_binding 主动路径,issue #470
continue; return;
} }
let app = match inner.app.lock().clone() { let app = match inner.app.lock().clone() {