refactor: use async instead of block_on

This commit is contained in:
MystiPanda
2024-06-29 19:02:37 +08:00
parent c1a201f358
commit 1293d25e1b
11 changed files with 81 additions and 74 deletions

View File

@@ -219,22 +219,18 @@ impl CoreManager {
}
/// 停止核心运行
pub fn stop_core(&self) -> Result<()> {
pub async fn stop_core(&self) -> Result<()> {
// 关闭tun模式
tauri::async_runtime::block_on(async move {
let mut disable = Mapping::new();
let mut tun = Mapping::new();
tun.insert("enable".into(), false.into());
disable.insert("tun".into(), tun.into());
log::debug!(target: "app", "disable tun mode");
let _ = clash_api::patch_configs(&disable).await;
});
let mut disable = Mapping::new();
let mut tun = Mapping::new();
tun.insert("enable".into(), false.into());
disable.insert("tun".into(), tun.into());
log::debug!(target: "app", "disable tun mode");
let _ = clash_api::patch_configs(&disable).await;
if *self.use_service_mode.lock() {
log::debug!(target: "app", "stop the core by service");
tauri::async_runtime::block_on(async move {
log_err!(service::stop_core_by_service().await);
});
log_err!(service::stop_core_by_service().await);
return Ok(());
}
@@ -265,7 +261,7 @@ impl CoreManager {
Config::verge().draft().clash_core = Some(clash_core);
// 更新订阅
Config::generate()?;
Config::generate().await?;
self.check_config()?;
@@ -293,7 +289,7 @@ impl CoreManager {
log::debug!(target: "app", "try to update clash config");
// 更新订阅
Config::generate()?;
Config::generate().await?;
// 检查订阅是否正常
self.check_config()?;