From d374ab4350a2243c9db54cb32280cf88368f1654 Mon Sep 17 00:00:00 2001 From: wonfen Date: Mon, 21 Sep 2026 22:46:58 +0800 Subject: [PATCH] refactor(enhance): unify discarded-key notice state --- src-tauri/src/enhance/mod.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/enhance/mod.rs b/src-tauri/src/enhance/mod.rs index db2b6eca2..fb5e4892b 100644 --- a/src-tauri/src/enhance/mod.rs +++ b/src-tauri/src/enhance/mod.rs @@ -384,24 +384,36 @@ fn discarded_note(key: String) -> (String, String) { ) } -static PENDING_DISCARDED_KEYS: Mutex> = Mutex::new(None); -static LAST_DISCARDED_KEYS: Mutex> = Mutex::new(Vec::new()); +struct DiscardedKeysNotice { + pending: Option, + last: Vec, +} + +static DISCARDED_KEYS_NOTICE: Mutex = Mutex::new(DiscardedKeysNotice { + pending: None, + last: Vec::new(), +}); pub(crate) fn take_discarded_keys_notice() -> Option { - PENDING_DISCARDED_KEYS.lock().take() + DISCARDED_KEYS_NOTICE.lock().pending.take() } /// One notice per distinct set, so regenerations with unchanged extensions stay quiet. fn notify_discarded_keys(keys: Vec) { - let mut last = LAST_DISCARDED_KEYS.lock(); - if *last == keys { + let mut notice = DISCARDED_KEYS_NOTICE.lock(); + if notice.last == keys { return; } - if !keys.is_empty() { - *PENDING_DISCARDED_KEYS.lock() = Some(keys.join(", ").into()); + let should_notify = !keys.is_empty(); + if should_notify { + notice.pending = Some(keys.join(", ").into()); + } + notice.last = keys; + drop(notice); + + if should_notify { Handle::notice_message("enhance::discarded_keys", ""); } - *last = keys; } /// 手动 merge/script 前保存 app 最终控制面值,只记录当前存在的键。