From b70d45b66a5e223d7190b2b5e62764d3833234c3 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Tue, 4 Nov 2025 07:58:14 +0800 Subject: [PATCH] fix: update profile handling to apply and discard changes correctly --- src-tauri/src/cmd/profile.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/cmd/profile.rs b/src-tauri/src/cmd/profile.rs index e2bcf3b61..e67fc7342 100644 --- a/src-tauri/src/cmd/profile.rs +++ b/src-tauri/src/cmd/profile.rs @@ -27,8 +27,8 @@ static CURRENT_SWITCHING_PROFILE: AtomicBool = AtomicBool::new(false); pub async fn get_profiles() -> CmdResult> { logging!(debug, Type::Cmd, "获取配置文件列表"); let draft = Config::profiles().await; - let latest = draft.latest_arc(); - Ok(latest) + let data = draft.data_arc(); + Ok(data) } /// 增强配置文件 @@ -100,9 +100,11 @@ pub async fn reorder_profile(active_id: String, over_id: String) -> CmdResult { match profiles_reorder_safe(&active_id, &over_id).await { Ok(_) => { logging!(info, Type::Cmd, "重新排序配置文件"); + Config::profiles().await.apply(); Ok(()) } Err(err) => { + Config::profiles().await.discard(); logging!(error, Type::Cmd, "重新排序配置文件失败: {}", err); Err(format!("重新排序配置文件失败: {}", err).into()) } @@ -120,12 +122,16 @@ pub async fn create_profile(item: PrfItem, file_data: Option) -> CmdResu logging!(info, Type::Cmd, "[创建订阅] 发送配置变更通知: {}", uid); handle::Handle::notify_profile_changed(uid.clone()); } + Config::profiles().await.apply(); Ok(()) } - Err(err) => match err.to_string().as_str() { - "the file already exists" => Err("the file already exists".into()), - _ => Err(format!("add profile error: {err}").into()), - }, + Err(err) => { + Config::profiles().await.discard(); + match err.to_string().as_str() { + "the file already exists" => Err("the file already exists".into()), + _ => Err(format!("add profile error: {err}").into()), + } + } } } @@ -133,8 +139,12 @@ pub async fn create_profile(item: PrfItem, file_data: Option) -> CmdResu #[tauri::command] pub async fn update_profile(index: String, option: Option) -> CmdResult { match feat::update_profile(&index, option.as_ref(), true, true).await { - Ok(_) => Ok(()), + Ok(_) => { + let _: () = Config::profiles().await.apply(); + Ok(()) + } Err(e) => { + Config::profiles().await.discard(); logging!(error, Type::Cmd, "{}", e); Err(e.to_string().into()) } @@ -144,12 +154,11 @@ pub async fn update_profile(index: String, option: Option) -> CmdResu /// 删除配置文件 #[tauri::command] pub async fn delete_profile(index: String) -> CmdResult { - println!("delete_profile: {}", index); // 使用Send-safe helper函数 let should_update = profiles_delete_item_safe(&index).await.stringify_err()?; profiles_save_file_safe().await.stringify_err()?; - if should_update { + Config::profiles().await.apply(); match CoreManager::global().update_config().await { Ok(_) => { handle::Handle::refresh_clash();