From d4cb16f4ffc56844ecbddfed3df416caa5aa9676 Mon Sep 17 00:00:00 2001 From: oomeow Date: Sun, 2 Nov 2025 22:33:50 +0800 Subject: [PATCH] perf: select proxy (#5284) * perf: improve select proxy for group * chore: update --- src-tauri/src/cmd/profile.rs | 11 ++++++----- src-tauri/src/core/tray/mod.rs | 1 - src/hooks/use-profiles.ts | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/cmd/profile.rs b/src-tauri/src/cmd/profile.rs index 9ab8e21a..949ddce1 100644 --- a/src-tauri/src/cmd/profile.rs +++ b/src-tauri/src/cmd/profile.rs @@ -570,14 +570,16 @@ pub async fn patch_profiles_config_by_profile_index(profile_index: String) -> Cm pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult { // 保存修改前检查是否有更新 update_interval let profiles = Config::profiles().await; - let should_refresh_timer = if let Ok(old_profile) = profiles.latest_ref().get_item(&index) { + let should_refresh_timer = if let Ok(old_profile) = profiles.latest_ref().get_item(&index) + && let Some(new_option) = profile.option.as_ref() + { let old_interval = old_profile.option.as_ref().and_then(|o| o.update_interval); - let new_interval = profile.option.as_ref().and_then(|o| o.update_interval); + let new_interval = new_option.update_interval; let old_allow_auto_update = old_profile .option .as_ref() .and_then(|o| o.allow_auto_update); - let new_allow_auto_update = profile.option.as_ref().and_then(|o| o.allow_auto_update); + let new_allow_auto_update = new_option.allow_auto_update; (old_interval != new_interval) || (old_allow_auto_update != new_allow_auto_update) } else { false @@ -589,14 +591,13 @@ pub async fn patch_profile(index: String, profile: PrfItem) -> CmdResult { // 如果更新间隔或允许自动更新变更,异步刷新定时器 if should_refresh_timer { - let index_clone = index.clone(); crate::process::AsyncHandler::spawn(move || async move { logging!(info, Type::Timer, "定时器更新间隔已变更,正在刷新定时器..."); if let Err(e) = crate::core::Timer::global().refresh().await { logging!(error, Type::Timer, "刷新定时器失败: {}", e); } else { // 刷新成功后发送自定义事件,不触发配置重载 - crate::core::handle::Handle::notify_timer_updated(index_clone); + crate::core::handle::Handle::notify_timer_updated(index); } }); } diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 474b0202..ef300bbe 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -308,7 +308,6 @@ impl Tray { let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false); let tun_mode_available = cmd::system::is_admin().unwrap_or_default() || service::is_service_available().await.is_ok(); - println!("tun_mode_available: {}", tun_mode_available); let mode = { Config::clash() .await diff --git a/src/hooks/use-profiles.ts b/src/hooks/use-profiles.ts index fdb73462..c517c835 100644 --- a/src/hooks/use-profiles.ts +++ b/src/hooks/use-profiles.ts @@ -62,7 +62,9 @@ export const useProfiles = () => { const patchCurrent = async (value: Partial) => { if (profiles?.current) { await patchProfile(profiles.current, value); - mutateProfiles(); + if (!value.selected) { + mutateProfiles(); + } } };