From ab136e463fb5ec450a33c0eaef40878d5bc9e478 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Tue, 4 Nov 2025 12:13:18 +0800 Subject: [PATCH] fix: change error handling in patch_profiles_config to return false when a switch is in progress fix: improve error handling in patch_profiles_config to prevent requests during profile switching fix: change error handling in patch_profiles_config to return false when a switch is in progress fix: ensure CURRENT_SWITCHING_PROFILE is reset after config updates in perform_config_update and patch_profiles_config --- src-tauri/src/cmd/profile.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/cmd/profile.rs b/src-tauri/src/cmd/profile.rs index bcdafab2..4af307cb 100644 --- a/src-tauri/src/cmd/profile.rs +++ b/src-tauri/src/cmd/profile.rs @@ -363,6 +363,9 @@ async fn perform_config_update( current_value: Option<&String>, current_profile: Option<&String>, ) -> CmdResult { + defer! { + CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release); + } let update_result = tokio::time::timeout( Duration::from_secs(30), CoreManager::global().update_config(), @@ -385,11 +388,7 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult { .is_err() { logging!(info, Type::Cmd, "当前正在切换配置,放弃请求"); - return Err("switch_in_progress".into()); - } - - defer! { - CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release); + return Ok(false); } let target_profile = profiles.current.as_ref(); @@ -410,6 +409,7 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult { && previous_profile.as_ref() != Some(switch_to_profile) && validate_new_profile(switch_to_profile).await.is_err() { + CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release); return Ok(false); } let _ = Config::profiles()