fix: improve error handling in patch_profiles_config to prevent requests during profile switching

This commit is contained in:
Tunglies
2025-11-04 12:27:01 +08:00
Unverified
parent 39fab9404f
commit 7dbea3e4a5
3 changed files with 12 additions and 8 deletions

View File

@@ -363,6 +363,9 @@ async fn perform_config_update(
current_value: Option<&String>,
current_profile: Option<&String>,
) -> CmdResult<bool> {
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<bool> {
.is_err()
{
logging!(info, Type::Cmd, "当前正在切换配置,放弃请求");
return Ok(false);
}
defer! {
CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release);
return Err("Profile switching is already in progress".into());
}
let target_profile = profiles.current.as_ref();
@@ -410,7 +409,8 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
&& previous_profile.as_ref() != Some(switch_to_profile)
&& validate_new_profile(switch_to_profile).await.is_err()
{
return Ok(false);
CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release);
return Err("Target profile validation failed".into());
}
let _ = Config::profiles()
.await

View File

@@ -714,5 +714,7 @@
"Unlock menu order": "Unlock menu order",
"Lock menu order": "Lock menu order",
"Open App Log": "Open App Log",
"Open Core Log": "Open Core Log"
"Open Core Log": "Open Core Log",
"Profile switching is already in progress": "Profile switching is already in progress",
"Target profile validation failed": "Target profile validation failed"
}

View File

@@ -715,5 +715,7 @@
"Lock menu order": "锁定菜单排序",
"Open App Log": "应用日志",
"Open Core Log": "内核日志",
"TPROXY Port": "TPROXY 透明代理端口"
"TPROXY Port": "TPROXY 透明代理端口",
"Profile switching is already in progress": "配置文件切换已在进行中",
"Target profile validation failed": "目标配置文件验证失败"
}