mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 23:13:44 +08:00
feat: auto select profile
This commit is contained in:
parent
624eb2a2ba
commit
1b7dafe743
@ -111,6 +111,7 @@ impl IProfiles {
|
|||||||
if item.uid.is_none() {
|
if item.uid.is_none() {
|
||||||
bail!("the uid should not be null");
|
bail!("the uid should not be null");
|
||||||
}
|
}
|
||||||
|
let uid = item.uid.clone();
|
||||||
|
|
||||||
// save the file data
|
// save the file data
|
||||||
// move the field value after save
|
// move the field value after save
|
||||||
@ -128,6 +129,12 @@ impl IProfiles {
|
|||||||
.with_context(|| format!("failed to write to file \"{}\"", file))?;
|
.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() {
|
if self.items.is_none() {
|
||||||
self.items = Some(vec![]);
|
self.items = Some(vec![]);
|
||||||
}
|
}
|
||||||
@ -135,6 +142,7 @@ impl IProfiles {
|
|||||||
if let Some(items) = self.items.as_mut() {
|
if let Some(items) = self.items.as_mut() {
|
||||||
items.push(item)
|
items.push(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.save_file()
|
self.save_file()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,10 +363,15 @@ impl IProfiles {
|
|||||||
}
|
}
|
||||||
// delete the original uid
|
// delete the original uid
|
||||||
if current == uid {
|
if current == uid {
|
||||||
self.current = match !items.is_empty() {
|
self.current = None;
|
||||||
true => items[0].uid.clone(),
|
for item in items.iter() {
|
||||||
false => None,
|
if item.itype == Some("remote".to_string())
|
||||||
};
|
|| item.itype == Some("local".to_string())
|
||||||
|
{
|
||||||
|
self.current = item.uid.clone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.items = Some(items);
|
self.items = Some(items);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user