refactor(coordinator): 合并 take_*_combo_hotkey_on_main_thread 三处复制
combo_hotkey / translation_hotkey / coding_agent_combo_hotkey 三个 take_*_on_main_thread 的主线程释放(issue #118)marshaling 体逐字相同,仅 take 字段不同。抽出共享 take_combo_monitor_on_main_thread(inner, slot), slot 闭包按 &Arc<Inner> 取回对应 Mutex<Option<ComboHotkeyMonitor>> 字段, 三处改为薄封装。action_hotkey 类已用 action_hotkey_slot 单独泛化,不动。 语义不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
db51e95fde
commit
cbf3be0d50
2 files changed
+18
-21
No files matched your search
@@ -593,28 +593,33 @@ pub(crate) fn switch_to_previous_style(inner: &Arc<Inner>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn take_combo_hotkey_on_main_thread(inner: &Arc<Inner>) {
|
||||
/// 在主线程上 `.take()` 一个 combo 监听槽。
|
||||
///
|
||||
/// 这三类 combo 热键(combo / translation / coding-agent)的「拿 app → 有则
|
||||
/// `run_on_main_thread` 里 take,无则直接 take」marshaling 语义逐字相同,只是 take
|
||||
/// 的字段不同(issue #118:监听器必须在主线程释放)。`slot` 闭包按 `&Arc<Inner>`
|
||||
/// 取回对应字段,消除三处复制。`action_hotkey` 类已用 `action_hotkey_slot` 单独泛化。
|
||||
pub(crate) fn take_combo_monitor_on_main_thread(
|
||||
inner: &Arc<Inner>,
|
||||
slot: impl Fn(&Arc<Inner>) -> &Mutex<Option<ComboHotkeyMonitor>> + Send + 'static,
|
||||
) {
|
||||
let app = inner.app.lock().clone();
|
||||
if let Some(app) = app {
|
||||
let inner = Arc::clone(inner);
|
||||
let _ = app.run_on_main_thread(move || {
|
||||
inner.combo_hotkey.lock().take();
|
||||
slot(&inner).lock().take();
|
||||
});
|
||||
} else {
|
||||
inner.combo_hotkey.lock().take();
|
||||
slot(inner).lock().take();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn take_combo_hotkey_on_main_thread(inner: &Arc<Inner>) {
|
||||
take_combo_monitor_on_main_thread(inner, |inner| &inner.combo_hotkey);
|
||||
}
|
||||
|
||||
pub(crate) fn take_translation_hotkey_on_main_thread(inner: &Arc<Inner>) {
|
||||
let app = inner.app.lock().clone();
|
||||
if let Some(app) = app {
|
||||
let inner = Arc::clone(inner);
|
||||
let _ = app.run_on_main_thread(move || {
|
||||
inner.translation_hotkey.lock().take();
|
||||
});
|
||||
} else {
|
||||
inner.translation_hotkey.lock().take();
|
||||
}
|
||||
take_combo_monitor_on_main_thread(inner, |inner| &inner.translation_hotkey);
|
||||
}
|
||||
|
||||
pub(crate) fn take_action_hotkey_on_main_thread(inner: &Arc<Inner>, kind: ActionHotkeyKind) {
|
||||
|
||||
@@ -237,15 +237,7 @@ pub(crate) fn take_coding_agent_hotkeys_on_main_thread(inner: &Arc<Inner>) {
|
||||
}
|
||||
|
||||
pub(crate) fn take_coding_agent_combo_hotkey_on_main_thread(inner: &Arc<Inner>) {
|
||||
let app = inner.app.lock().clone();
|
||||
if let Some(app) = app {
|
||||
let inner = Arc::clone(inner);
|
||||
let _ = app.run_on_main_thread(move || {
|
||||
inner.coding_agent_combo_hotkey.lock().take();
|
||||
});
|
||||
} else {
|
||||
inner.coding_agent_combo_hotkey.lock().take();
|
||||
}
|
||||
take_combo_monitor_on_main_thread(inner, |inner| &inner.coding_agent_combo_hotkey);
|
||||
}
|
||||
|
||||
/// 快取用:抓当前选中文本 → Claude 润色 → 回插(替换选区)。全程胶囊反馈。
|
||||
|
||||
Reference in new issue
Block a user