fix(less-computer): 「hotkey disabled」只在状态翻转时打一次——日志不再被它刷爆 (#873)

coding_agent_hotkey_supervisor_loop 每 5s 轮询一次绑定。没配 Less Computer
语音键的用户,每一轮都会落到同一条禁用分支并无条件打一行
「[less-computer] hotkey disabled」,稳定产出 720 行/小时。

实测一份连续跑了六天的 openless.log 里,这一行占了全部日志的 95% 以上
(132416 行中约 12.7 万行),文件涨到 11MB:真正有用的会话/错误日志被冲得
很难翻,日志轮转也被它提前触发,把更早的历史挤掉——排查线上问题时相当致命。

讽刺的是它刷得最凶的恰恰是没在用这个功能的人:一旦配上语音键,函数会走到
安装分支,反而一行都不打。

改成只在状态真正翻转成「禁用」时打一次,重新装上语音键时清掉标志位,
下次禁用仍会再打。禁用/启用的行为本身完全不变,只动日志。

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
bigsongandClaude Fable 5 authored and GitHub committed 2026-08-02 20:56:44 +08:00
1 parent 2409036ca9
commit e484cd11cf
1 file changed
+14 -1
@@ -313,6 +313,16 @@ pub(super) fn coding_agent_hotkey_supervisor_loop(inner: Arc<Inner>) {
}
}
/// 「Less Computer 语音键已禁用」是否已经打过日志。
///
/// supervisor 每 5s 轮询一次,没配语音键的用户每轮都会落到同一条禁用分支。无条件
/// 打印会稳定产出 720 行/小时的同一句话 —— 实测一份跑了六天的 openless.log 里它占
/// 了 95% 以上,真正有用的会话日志被冲得很难找,日志轮转也被它提前触发。
/// 只在状态翻转成禁用时打一次;重新装上语音键时清掉,下次禁用还会再打。
#[cfg(target_os = "macos")]
static LESS_COMPUTER_HOTKEY_DISABLED_LOGGED: std::sync::atomic::AtomicBool =
std::sync::atomic::AtomicBool::new(false);
pub(super) fn update_coding_agent_hotkey_binding_now(inner: &Arc<Inner>) {
#[cfg(not(target_os = "macos"))]
{
@@ -326,13 +336,16 @@ pub(super) fn update_coding_agent_hotkey_binding_now(inner: &Arc<Inner>) {
let prefs = inner.prefs.get();
let Some(binding) = prefs.coding_agent_voice_hotkey.clone() else {
take_coding_agent_hotkeys_on_main_thread(inner);
log::info!("[less-computer] hotkey disabled");
if !LESS_COMPUTER_HOTKEY_DISABLED_LOGGED.swap(true, Ordering::SeqCst) {
log::info!("[less-computer] hotkey disabled");
}
return;
};
if !prefs.coding_agent_enabled || is_unconfigured_shortcut(&binding) {
take_coding_agent_hotkeys_on_main_thread(inner);
return;
}
LESS_COMPUTER_HOTKEY_DISABLED_LOGGED.store(false, Ordering::SeqCst);
if let Some(modifier_binding) = less_computer_modifier_binding(&binding) {
take_coding_agent_combo_hotkey_on_main_thread(inner);