Skip to content

Commit

Permalink
feat: auto select profile
Browse files Browse the repository at this point in the history
  • Loading branch information
MystiPanda committed Jul 30, 2024
1 parent 624eb2a commit 1b7dafe
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src-tauri/src/config/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -128,13 +129,20 @@ 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![]);
}

if let Some(items) = self.items.as_mut() {
items.push(item)
}

self.save_file()
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b7dafe

Please sign in to comment.