fix: improve error handling in patch_profiles_config to prevent requests during profile switching
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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": "目标配置文件验证失败"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user