From a5d0b8dacbf82bdcbb592159821f6897827f346e Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:08:07 +0800 Subject: [PATCH] refactor(config): name prfitem constructor for what it builds new_seq_item states that a fresh item is built from a template; the from_ prefix wrongly implied an existing source. append_companion_item returns the uid directly: append_item bails on a missing uid, so the Option was always Some on the Ok path. --- src-tauri/src/config/prfitem.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index 23278dcfc..eafb29cf9 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -182,9 +182,11 @@ impl PrfItem { } } - async fn append_companion_item(item: &mut Self) -> Result> { + async fn append_companion_item(item: &mut Self) -> Result { profiles::profiles_append_item_safe(item).await?; - Ok(item.uid.clone()) + item.uid + .clone() + .ok_or_else(|| anyhow::anyhow!("appended companion item has no uid")) } async fn ensure_companion_items( @@ -195,19 +197,19 @@ impl PrfItem { groups: &mut Option, ) -> Result<()> { if merge.is_none() { - *merge = Self::append_companion_item(&mut Self::from_merge(None)).await?; + *merge = Some(Self::append_companion_item(&mut Self::from_merge(None)).await?); } if script.is_none() { - *script = Self::append_companion_item(&mut Self::from_script(None)).await?; + *script = Some(Self::append_companion_item(&mut Self::from_script(None)).await?); } if rules.is_none() { - *rules = Self::append_companion_item(&mut Self::from_rules()).await?; + *rules = Some(Self::append_companion_item(&mut Self::from_rules()).await?); } if proxies.is_none() { - *proxies = Self::append_companion_item(&mut Self::from_proxies()).await?; + *proxies = Some(Self::append_companion_item(&mut Self::from_proxies()).await?); } if groups.is_none() { - *groups = Self::append_companion_item(&mut Self::from_groups()).await?; + *groups = Some(Self::append_companion_item(&mut Self::from_groups()).await?); } Ok(()) } @@ -444,7 +446,7 @@ impl PrfItem { } } - fn from_seq_item(prefix: &str, itype: &str, template: &str) -> Self { + fn new_seq_item(prefix: &str, itype: &str, template: &str) -> Self { let uid = help::get_uid(prefix).into(); let file = format!("{uid}.yaml").into(); // yaml ext @@ -459,15 +461,15 @@ impl PrfItem { } fn from_rules() -> Self { - Self::from_seq_item("r", "rules", tmpl::ITEM_RULES) + Self::new_seq_item("r", "rules", tmpl::ITEM_RULES) } fn from_proxies() -> Self { - Self::from_seq_item("p", "proxies", tmpl::ITEM_PROXIES) + Self::new_seq_item("p", "proxies", tmpl::ITEM_PROXIES) } fn from_groups() -> Self { - Self::from_seq_item("g", "groups", tmpl::ITEM_GROUPS) + Self::new_seq_item("g", "groups", tmpl::ITEM_GROUPS) } pub(crate) async fn read_file(&self) -> Result {