From 41fc13cfe24a3d0c89c380396185faf32a9265cf Mon Sep 17 00:00:00 2001 From: wonfen Date: Sat, 21 Jun 2025 22:39:12 +0800 Subject: [PATCH] fix: format & update --- UPDATELOG.md | 1 + src-tauri/src/core/async_proxy_query.rs | 15 +++------------ src-tauri/src/core/core.rs | 12 ++++++------ src-tauri/src/core/event_driven_proxy.rs | 2 +- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index ae48099dc..2cf97bb57 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -12,6 +12,7 @@ ### 🚀 优化改进 - 优化重构订阅切换逻辑,可以随时中断载入过程,防止卡死 +- 引入事件驱动代理管理器,优化代理配置更新逻辑,防止卡死 ## v2.3.1 diff --git a/src-tauri/src/core/async_proxy_query.rs b/src-tauri/src/core/async_proxy_query.rs index b03c0d688..a82790448 100644 --- a/src-tauri/src/core/async_proxy_query.rs +++ b/src-tauri/src/core/async_proxy_query.rs @@ -3,21 +3,12 @@ use serde::{Deserialize, Serialize}; use tokio::process::Command; use tokio::time::{timeout, Duration}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct AsyncAutoproxy { pub enable: bool, pub url: String, } -impl Default for AsyncAutoproxy { - fn default() -> Self { - Self { - enable: false, - url: String::new(), - } - } -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AsyncSysproxy { pub enable: bool, @@ -131,7 +122,7 @@ impl AsyncProxyQuery { #[cfg(target_os = "macos")] async fn get_auto_proxy_impl() -> Result { // macOS: 使用 scutil --proxy 命令 - let output = Command::new("scutil").args(&["--proxy"]).output().await?; + let output = Command::new("scutil").args(["--proxy"]).output().await?; if !output.status.success() { return Ok(AsyncAutoproxy::default()); @@ -276,7 +267,7 @@ impl AsyncProxyQuery { #[cfg(target_os = "macos")] async fn get_system_proxy_impl() -> Result { - let output = Command::new("scutil").args(&["--proxy"]).output().await?; + let output = Command::new("scutil").args(["--proxy"]).output().await?; if !output.status.success() { return Ok(AsyncSysproxy::default()); diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index 12623176d..c1d7e2e80 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -524,7 +524,7 @@ impl CoreManager { ) -> Result<(Vec, String)> { let output = if cfg!(windows) { tokio::process::Command::new("tasklist") - .args(&[ + .args([ "/FI", &format!("IMAGENAME eq {}", process_name), "/FO", @@ -569,7 +569,7 @@ impl CoreManager { } } else { // Unix系统直接解析PID列表 - for pid_str in stdout.trim().split_whitespace() { + for pid_str in stdout.split_whitespace() { if let Ok(pid) = pid_str.parse::() { pids.push(pid); } @@ -592,14 +592,14 @@ impl CoreManager { let success = if cfg!(windows) { tokio::process::Command::new("taskkill") - .args(&["/F", "/PID", &pid.to_string()]) + .args(["/F", "/PID", &pid.to_string()]) .output() .await .map(|output| output.status.success()) .unwrap_or(false) } else { tokio::process::Command::new("kill") - .args(&["-9", &pid.to_string()]) + .args(["-9", &pid.to_string()]) .output() .await .map(|output| output.status.success()) @@ -649,12 +649,12 @@ impl CoreManager { async fn is_process_running(&self, pid: u32) -> Result { let output = if cfg!(windows) { tokio::process::Command::new("tasklist") - .args(&["/FI", &format!("PID eq {}", pid), "/FO", "CSV", "/NH"]) + .args(["/FI", &format!("PID eq {}", pid), "/FO", "CSV", "/NH"]) .output() .await? } else { tokio::process::Command::new("ps") - .args(&["-p", &pid.to_string()]) + .args(["-p", &pid.to_string()]) .output() .await? }; diff --git a/src-tauri/src/core/event_driven_proxy.rs b/src-tauri/src/core/event_driven_proxy.rs index 28f9a095c..97cd28531 100644 --- a/src-tauri/src/core/event_driven_proxy.rs +++ b/src-tauri/src/core/event_driven_proxy.rs @@ -85,7 +85,7 @@ struct ProxyConfig { guard_enabled: bool, } -static PROXY_MANAGER: Lazy = Lazy::new(|| EventDrivenProxyManager::new()); +static PROXY_MANAGER: Lazy = Lazy::new(EventDrivenProxyManager::new); impl EventDrivenProxyManager { pub fn global() -> &'static EventDrivenProxyManager {