mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: format & update
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
### 🚀 优化改进
|
### 🚀 优化改进
|
||||||
|
|
||||||
- 优化重构订阅切换逻辑,可以随时中断载入过程,防止卡死
|
- 优化重构订阅切换逻辑,可以随时中断载入过程,防止卡死
|
||||||
|
- 引入事件驱动代理管理器,优化代理配置更新逻辑,防止卡死
|
||||||
|
|
||||||
## v2.3.1
|
## v2.3.1
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,12 @@ use serde::{Deserialize, Serialize};
|
|||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
use tokio::time::{timeout, Duration};
|
use tokio::time::{timeout, Duration};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
pub struct AsyncAutoproxy {
|
pub struct AsyncAutoproxy {
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AsyncAutoproxy {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
enable: false,
|
|
||||||
url: String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AsyncSysproxy {
|
pub struct AsyncSysproxy {
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
@@ -131,7 +122,7 @@ impl AsyncProxyQuery {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
async fn get_auto_proxy_impl() -> Result<AsyncAutoproxy> {
|
async fn get_auto_proxy_impl() -> Result<AsyncAutoproxy> {
|
||||||
// macOS: 使用 scutil --proxy 命令
|
// 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() {
|
if !output.status.success() {
|
||||||
return Ok(AsyncAutoproxy::default());
|
return Ok(AsyncAutoproxy::default());
|
||||||
@@ -276,7 +267,7 @@ impl AsyncProxyQuery {
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
async fn get_system_proxy_impl() -> Result<AsyncSysproxy> {
|
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() {
|
if !output.status.success() {
|
||||||
return Ok(AsyncSysproxy::default());
|
return Ok(AsyncSysproxy::default());
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ impl CoreManager {
|
|||||||
) -> Result<(Vec<u32>, String)> {
|
) -> Result<(Vec<u32>, String)> {
|
||||||
let output = if cfg!(windows) {
|
let output = if cfg!(windows) {
|
||||||
tokio::process::Command::new("tasklist")
|
tokio::process::Command::new("tasklist")
|
||||||
.args(&[
|
.args([
|
||||||
"/FI",
|
"/FI",
|
||||||
&format!("IMAGENAME eq {}", process_name),
|
&format!("IMAGENAME eq {}", process_name),
|
||||||
"/FO",
|
"/FO",
|
||||||
@@ -569,7 +569,7 @@ impl CoreManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unix系统直接解析PID列表
|
// 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>() {
|
if let Ok(pid) = pid_str.parse::<u32>() {
|
||||||
pids.push(pid);
|
pids.push(pid);
|
||||||
}
|
}
|
||||||
@@ -592,14 +592,14 @@ impl CoreManager {
|
|||||||
|
|
||||||
let success = if cfg!(windows) {
|
let success = if cfg!(windows) {
|
||||||
tokio::process::Command::new("taskkill")
|
tokio::process::Command::new("taskkill")
|
||||||
.args(&["/F", "/PID", &pid.to_string()])
|
.args(["/F", "/PID", &pid.to_string()])
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
.map(|output| output.status.success())
|
.map(|output| output.status.success())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
} else {
|
} else {
|
||||||
tokio::process::Command::new("kill")
|
tokio::process::Command::new("kill")
|
||||||
.args(&["-9", &pid.to_string()])
|
.args(["-9", &pid.to_string()])
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
.map(|output| output.status.success())
|
.map(|output| output.status.success())
|
||||||
@@ -649,12 +649,12 @@ impl CoreManager {
|
|||||||
async fn is_process_running(&self, pid: u32) -> Result<bool> {
|
async fn is_process_running(&self, pid: u32) -> Result<bool> {
|
||||||
let output = if cfg!(windows) {
|
let output = if cfg!(windows) {
|
||||||
tokio::process::Command::new("tasklist")
|
tokio::process::Command::new("tasklist")
|
||||||
.args(&["/FI", &format!("PID eq {}", pid), "/FO", "CSV", "/NH"])
|
.args(["/FI", &format!("PID eq {}", pid), "/FO", "CSV", "/NH"])
|
||||||
.output()
|
.output()
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
tokio::process::Command::new("ps")
|
tokio::process::Command::new("ps")
|
||||||
.args(&["-p", &pid.to_string()])
|
.args(["-p", &pid.to_string()])
|
||||||
.output()
|
.output()
|
||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ struct ProxyConfig {
|
|||||||
guard_enabled: bool,
|
guard_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
static PROXY_MANAGER: Lazy<EventDrivenProxyManager> = Lazy::new(|| EventDrivenProxyManager::new());
|
static PROXY_MANAGER: Lazy<EventDrivenProxyManager> = Lazy::new(EventDrivenProxyManager::new);
|
||||||
|
|
||||||
impl EventDrivenProxyManager {
|
impl EventDrivenProxyManager {
|
||||||
pub fn global() -> &'static EventDrivenProxyManager {
|
pub fn global() -> &'static EventDrivenProxyManager {
|
||||||
|
|||||||
Reference in New Issue
Block a user