diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index 7ddeec3..a332f60 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -80,7 +80,7 @@ impl Sysopt { } /// init the sysproxy - pub fn update_sysproxy(&self) -> Result<()> { + pub async fn update_sysproxy(&self) -> Result<()> { let _ = self.update_sysproxy.lock(); let port = Config::verge() @@ -125,7 +125,7 @@ impl Sysopt { #[cfg(target_os = "windows")] { if !enable { - return self.reset_sysproxy(); + return self.reset_sysproxy().await; } use crate::core::handle::Handle; use crate::utils::dirs; @@ -143,26 +143,22 @@ impl Sysopt { let shell = app_handle.shell(); let output = if pac { let address = format!("http://{}:{}/pac", "127.0.0.1", pac_port); - let output = tauri::async_runtime::block_on(async move { - shell - .command(sysproxy_exe.as_path().to_str().unwrap()) - .args(["opac", address.as_str()]) - .output() - .await - .unwrap() - }); + let output = shell + .command(sysproxy_exe.as_path().to_str().unwrap()) + .args(["opac", address.as_str()]) + .output() + .await + .unwrap(); output } else { let address = format!("{}:{}", "127.0.0.1", port); let bypass = get_bypass(); - let output = tauri::async_runtime::block_on(async move { - shell - .command(sysproxy_exe.as_path().to_str().unwrap()) - .args(["global", address.as_str(), bypass.as_ref()]) - .output() - .await - .unwrap() - }); + let output = shell + .command(sysproxy_exe.as_path().to_str().unwrap()) + .args(["global", address.as_str(), bypass.as_ref()]) + .output() + .await + .unwrap(); output }; @@ -175,7 +171,7 @@ impl Sysopt { } /// reset the sysproxy - pub fn reset_sysproxy(&self) -> Result<()> { + pub async fn reset_sysproxy(&self) -> Result<()> { let _ = self.reset_sysproxy.lock(); //直接关闭所有代理 #[cfg(not(target_os = "windows"))] @@ -205,14 +201,12 @@ impl Sysopt { } let shell = app_handle.shell(); - let output = tauri::async_runtime::block_on(async move { - shell - .command(sysproxy_exe.as_path().to_str().unwrap()) - .args(["set", "1"]) - .output() - .await - .unwrap() - }); + let output = shell + .command(sysproxy_exe.as_path().to_str().unwrap()) + .args(["set", "1"]) + .output() + .await + .unwrap(); if !output.status.success() { bail!("sysproxy exe run failed"); diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 40ab351..261f2ea 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -237,7 +237,7 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { } if should_update_sysproxy { - sysopt::Sysopt::global().update_sysproxy()?; + sysopt::Sysopt::global().update_sysproxy().await?; } if let Some(hotkeys) = patch.hotkeys { diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index f31dee9..6c7a28b 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -94,7 +94,7 @@ pub async fn resolve_setup(app: &mut App) { } log_err!(sysopt::Sysopt::global().init_launch()); - log_err!(sysopt::Sysopt::global().update_sysproxy()); + log_err!(sysopt::Sysopt::global().update_sysproxy().await); log_err!(sysopt::Sysopt::global().init_guard_sysproxy()); log_err!(handle::Handle::update_systray_part()); @@ -104,8 +104,8 @@ pub async fn resolve_setup(app: &mut App) { /// reset system proxy pub fn resolve_reset() { - log_err!(sysopt::Sysopt::global().reset_sysproxy()); tauri::async_runtime::block_on(async move { + log_err!(sysopt::Sysopt::global().reset_sysproxy().await); log_err!(CoreManager::global().stop_core().await); log_err!(service::unset_dns_by_service().await); });