mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
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
This commit is contained in:
@@ -363,6 +363,9 @@ async fn perform_config_update(
|
|||||||
current_value: Option<&String>,
|
current_value: Option<&String>,
|
||||||
current_profile: Option<&String>,
|
current_profile: Option<&String>,
|
||||||
) -> CmdResult<bool> {
|
) -> CmdResult<bool> {
|
||||||
|
defer! {
|
||||||
|
CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release);
|
||||||
|
}
|
||||||
let update_result = tokio::time::timeout(
|
let update_result = tokio::time::timeout(
|
||||||
Duration::from_secs(30),
|
Duration::from_secs(30),
|
||||||
CoreManager::global().update_config(),
|
CoreManager::global().update_config(),
|
||||||
@@ -385,11 +388,7 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
|
|||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
logging!(info, Type::Cmd, "当前正在切换配置,放弃请求");
|
logging!(info, Type::Cmd, "当前正在切换配置,放弃请求");
|
||||||
return Err("switch_in_progress".into());
|
return Ok(false);
|
||||||
}
|
|
||||||
|
|
||||||
defer! {
|
|
||||||
CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_profile = profiles.current.as_ref();
|
let target_profile = profiles.current.as_ref();
|
||||||
@@ -410,6 +409,7 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
|
|||||||
&& previous_profile.as_ref() != Some(switch_to_profile)
|
&& previous_profile.as_ref() != Some(switch_to_profile)
|
||||||
&& validate_new_profile(switch_to_profile).await.is_err()
|
&& validate_new_profile(switch_to_profile).await.is_err()
|
||||||
{
|
{
|
||||||
|
CURRENT_SWITCHING_PROFILE.store(false, Ordering::Release);
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
let _ = Config::profiles()
|
let _ = Config::profiles()
|
||||||
|
|||||||
Reference in New Issue
Block a user