From 7b35ee513ad886a2542f13c752be2cb5560c9871 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sun, 17 Aug 2025 15:58:20 +0800 Subject: [PATCH] refactor: convert async functions to synchronous for service management --- src-tauri/src/cmd/uwp.rs | 2 +- src-tauri/src/core/event_driven_proxy.rs | 10 ++++++++-- src-tauri/src/core/service.rs | 4 ++-- src-tauri/src/feat/clash.rs | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/cmd/uwp.rs b/src-tauri/src/cmd/uwp.rs index d6b98655..8bf9cec7 100644 --- a/src-tauri/src/cmd/uwp.rs +++ b/src-tauri/src/cmd/uwp.rs @@ -24,5 +24,5 @@ mod platform { /// Command exposed to Tauri #[tauri::command] pub async fn invoke_uwp_tool() -> CmdResult { - platform::invoke_uwp_tool() + platform::invoke_uwp_tool().await } diff --git a/src-tauri/src/core/event_driven_proxy.rs b/src-tauri/src/core/event_driven_proxy.rs index af416e72..8f448565 100644 --- a/src-tauri/src/core/event_driven_proxy.rs +++ b/src-tauri/src/core/event_driven_proxy.rs @@ -518,7 +518,10 @@ impl EventDrivenProxyManager { #[cfg(target_os = "windows")] { - Self::execute_sysproxy_command(&["pac", expected_url]).await; + logging_error!( + Type::System, + Self::execute_sysproxy_command(&["pac", expected_url]) + ); } } @@ -531,7 +534,10 @@ impl EventDrivenProxyManager { #[cfg(target_os = "windows")] { let address = format!("{}:{}", expected.host, expected.port); - Self::execute_sysproxy_command(&["global", &address, &expected.bypass]).await; + logging_error!( + Type::System, + Self::execute_sysproxy_command(&["global", &address, &expected.bypass]) + ); } } diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 036c2d30..cb684702 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -180,7 +180,7 @@ pub fn install_service() -> Result<()> { } #[cfg(target_os = "windows")] -pub async fn reinstall_service() -> Result<()> { +pub fn reinstall_service() -> Result<()> { logging!(info, Type::Service, true, "reinstall service"); // 获取当前服务状态 @@ -308,7 +308,7 @@ pub fn install_service() -> Result<()> { } #[cfg(target_os = "linux")] -pub async fn reinstall_service() -> Result<()> { +pub fn reinstall_service() -> Result<()> { logging!(info, Type::Service, true, "reinstall service"); // 获取当前服务状态 diff --git a/src-tauri/src/feat/clash.rs b/src-tauri/src/feat/clash.rs index 97ab0b77..67a7d94b 100644 --- a/src-tauri/src/feat/clash.rs +++ b/src-tauri/src/feat/clash.rs @@ -34,7 +34,7 @@ pub fn restart_app() { logging!(error, Type::Core, "Failed to get app handle for restart"); return; }; - std::thread::sleep(std::time::Duration::from_secs(1)); + tokio::time::sleep(std::time::Duration::from_secs(1)).await; tauri::process::restart(&app_handle.env()); }); }