From 1b7dafe743660358b92400ac93aef7b55830c9ff Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Tue, 30 Jul 2024 09:06:12 +0800 Subject: [PATCH] feat: auto select profile --- src-tauri/src/config/profiles.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/config/profiles.rs b/src-tauri/src/config/profiles.rs index 260eba76f..a535457b1 100644 --- a/src-tauri/src/config/profiles.rs +++ b/src-tauri/src/config/profiles.rs @@ -111,6 +111,7 @@ impl IProfiles { if item.uid.is_none() { bail!("the uid should not be null"); } + let uid = item.uid.clone(); // save the file data // move the field value after save @@ -128,6 +129,12 @@ impl IProfiles { .with_context(|| format!("failed to write to file \"{}\"", file))?; } + if self.current.is_none() + && (item.itype == Some("remote".to_string()) || item.itype == Some("local".to_string())) + { + self.current = uid; + } + if self.items.is_none() { self.items = Some(vec![]); } @@ -135,6 +142,7 @@ impl IProfiles { if let Some(items) = self.items.as_mut() { items.push(item) } + self.save_file() } @@ -355,10 +363,15 @@ impl IProfiles { } // delete the original uid if current == uid { - self.current = match !items.is_empty() { - true => items[0].uid.clone(), - false => None, - }; + self.current = None; + for item in items.iter() { + if item.itype == Some("remote".to_string()) + || item.itype == Some("local".to_string()) + { + self.current = item.uid.clone(); + break; + } + } } self.items = Some(items);