mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-28 16:30:52 +08:00
fix: format & update
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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?
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user