fix: format & update

This commit is contained in:
wonfen
2025-06-21 22:39:12 +08:00
parent 5fde5dcc7c
commit 41fc13cfe2
4 changed files with 11 additions and 19 deletions

View File

@@ -12,6 +12,7 @@
### 🚀 优化改进
- 优化重构订阅切换逻辑,可以随时中断载入过程,防止卡死
- 引入事件驱动代理管理器,优化代理配置更新逻辑,防止卡死
## v2.3.1

View File

@@ -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<AsyncAutoproxy> {
// 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<AsyncSysproxy> {
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());

View File

@@ -524,7 +524,7 @@ impl CoreManager {
) -> Result<(Vec<u32>, 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::<u32>() {
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<bool> {
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?
};

View File

@@ -85,7 +85,7 @@ struct ProxyConfig {
guard_enabled: bool,
}
static PROXY_MANAGER: Lazy<EventDrivenProxyManager> = Lazy::new(|| EventDrivenProxyManager::new());
static PROXY_MANAGER: Lazy<EventDrivenProxyManager> = Lazy::new(EventDrivenProxyManager::new);
impl EventDrivenProxyManager {
pub fn global() -> &'static EventDrivenProxyManager {