mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 19:56:50 +08:00
refactor: rm update item block_on
This commit is contained in:
parent
dc941575fe
commit
c8e6f3a627
|
@ -27,41 +27,35 @@ impl ProfilesN {
|
||||||
|
|
||||||
/// 更新单个配置
|
/// 更新单个配置
|
||||||
pub async fn update_item(&self, uid: String, option: Option<PrfOption>) -> Result<()> {
|
pub async fn update_item(&self, uid: String, option: Option<PrfOption>) -> Result<()> {
|
||||||
let (url, opt) = {
|
let url_opt = {
|
||||||
let profiles = self.config.lock();
|
let profiles = self.config.lock();
|
||||||
let item = profiles.get_item(&uid)?;
|
let item = profiles.get_item(&uid)?;
|
||||||
|
let is_remote = item.itype.as_ref().map_or(false, |s| s == "remote");
|
||||||
|
|
||||||
if let Some(typ) = item.itype.as_ref() {
|
if !is_remote {
|
||||||
// maybe only valid for `local` profile
|
None // 直接更新
|
||||||
if *typ != "remote" {
|
} else if item.url.is_none() {
|
||||||
// reactivate the config
|
|
||||||
if Some(uid) == profiles.get_current() {
|
|
||||||
drop(profiles);
|
|
||||||
tauri::async_runtime::block_on(async {
|
|
||||||
CoreManager::global().activate_config().await
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if item.url.is_none() {
|
|
||||||
bail!("failed to get the profile item url");
|
bail!("failed to get the profile item url");
|
||||||
|
} else {
|
||||||
|
Some((item.url.clone().unwrap(), item.option.clone()))
|
||||||
}
|
}
|
||||||
(item.url.clone().unwrap(), item.option.clone())
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let merged_opt = PrfOption::merge(opt, option);
|
let should_update = match url_opt {
|
||||||
let item = PrfItem::from_url(&url, None, None, merged_opt).await?;
|
Some((url, opt)) => {
|
||||||
|
let merged_opt = PrfOption::merge(opt, option);
|
||||||
|
let item = PrfItem::from_url(&url, None, None, merged_opt).await?;
|
||||||
|
|
||||||
let mut profiles = self.config.lock();
|
let mut profiles = self.config.lock();
|
||||||
profiles.update_item(uid.clone(), item)?;
|
profiles.update_item(uid.clone(), item)?;
|
||||||
|
|
||||||
// reactivate the profile
|
Some(uid) == profiles.get_current()
|
||||||
if Some(uid) == profiles.get_current() {
|
}
|
||||||
drop(profiles);
|
None => true,
|
||||||
tauri::async_runtime::block_on(async {
|
};
|
||||||
CoreManager::global().activate_config().await
|
|
||||||
})?;
|
if should_update {
|
||||||
|
CoreManager::global().activate_config().await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user