mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: improve error handling for application handle retrieval (#3860)
* fix: improve error handling for application handle retrieval * fix: correct argument passing for command execution and improve URL stripping logic
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
use anyhow::anyhow;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
@@ -71,7 +73,7 @@ impl AsyncProxyQuery {
|
|||||||
async fn get_auto_proxy_impl() -> Result<AsyncAutoproxy> {
|
async fn get_auto_proxy_impl() -> Result<AsyncAutoproxy> {
|
||||||
// Windows: 使用 netsh winhttp show proxy 命令
|
// Windows: 使用 netsh winhttp show proxy 命令
|
||||||
let output = Command::new("netsh")
|
let output = Command::new("netsh")
|
||||||
.args(&["winhttp", "show", "proxy"])
|
.args(["winhttp", "show", "proxy"])
|
||||||
.output()
|
.output()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ impl AsyncProxyQuery {
|
|||||||
|
|
||||||
// 尝试使用 gsettings 获取 GNOME 代理设置
|
// 尝试使用 gsettings 获取 GNOME 代理设置
|
||||||
let output = Command::new("gsettings")
|
let output = Command::new("gsettings")
|
||||||
.args(&["get", "org.gnome.system.proxy", "mode"])
|
.args(["get", "org.gnome.system.proxy", "mode"])
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -182,7 +184,7 @@ impl AsyncProxyQuery {
|
|||||||
if mode.contains("auto") {
|
if mode.contains("auto") {
|
||||||
// 获取 PAC URL
|
// 获取 PAC URL
|
||||||
let pac_output = Command::new("gsettings")
|
let pac_output = Command::new("gsettings")
|
||||||
.args(&["get", "org.gnome.system.proxy", "autoconfig-url"])
|
.args(["get", "org.gnome.system.proxy", "autoconfig-url"])
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -212,7 +214,7 @@ impl AsyncProxyQuery {
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
async fn get_system_proxy_impl() -> Result<AsyncSysproxy> {
|
async fn get_system_proxy_impl() -> Result<AsyncSysproxy> {
|
||||||
let output = Command::new("netsh")
|
let output = Command::new("netsh")
|
||||||
.args(&["winhttp", "show", "proxy"])
|
.args(["winhttp", "show", "proxy"])
|
||||||
.output()
|
.output()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -333,7 +335,7 @@ impl AsyncProxyQuery {
|
|||||||
|
|
||||||
// 尝试使用 gsettings 获取 GNOME 代理设置
|
// 尝试使用 gsettings 获取 GNOME 代理设置
|
||||||
let mode_output = Command::new("gsettings")
|
let mode_output = Command::new("gsettings")
|
||||||
.args(&["get", "org.gnome.system.proxy", "mode"])
|
.args(["get", "org.gnome.system.proxy", "mode"])
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -345,12 +347,12 @@ impl AsyncProxyQuery {
|
|||||||
if mode.contains("manual") {
|
if mode.contains("manual") {
|
||||||
// 获取HTTP代理设置
|
// 获取HTTP代理设置
|
||||||
let host_result = Command::new("gsettings")
|
let host_result = Command::new("gsettings")
|
||||||
.args(&["get", "org.gnome.system.proxy.http", "host"])
|
.args(["get", "org.gnome.system.proxy.http", "host"])
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let port_result = Command::new("gsettings")
|
let port_result = Command::new("gsettings")
|
||||||
.args(&["get", "org.gnome.system.proxy.http", "port"])
|
.args(["get", "org.gnome.system.proxy.http", "port"])
|
||||||
.output()
|
.output()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -390,10 +392,10 @@ impl AsyncProxyQuery {
|
|||||||
let url = proxy_url.trim();
|
let url = proxy_url.trim();
|
||||||
|
|
||||||
// 移除协议前缀
|
// 移除协议前缀
|
||||||
let url = if url.starts_with("http://") {
|
let url = if let Some(stripped) = url.strip_prefix("http://") {
|
||||||
&url[7..]
|
stripped
|
||||||
} else if url.starts_with("https://") {
|
} else if let Some(stripped) = url.strip_prefix("https://") {
|
||||||
&url[8..]
|
stripped
|
||||||
} else {
|
} else {
|
||||||
url
|
url
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ impl EventDrivenProxyManager {
|
|||||||
use tauri_plugin_shell::ShellExt;
|
use tauri_plugin_shell::ShellExt;
|
||||||
|
|
||||||
let app_handle = match Handle::global().app_handle() {
|
let app_handle = match Handle::global().app_handle() {
|
||||||
Ok(handle) => handle,
|
Some(handle) => handle,
|
||||||
Err(e) => {
|
None => {
|
||||||
log::error!(target: "app", "获取应用句柄失败: {}", e);
|
log::error!(target: "app", "获取应用句柄失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
use sysproxy::{Autoproxy, Sysproxy};
|
use sysproxy::{Autoproxy, Sysproxy};
|
||||||
use tauri::async_runtime::Mutex as TokioMutex;
|
use tauri::async_runtime::Mutex as TokioMutex;
|
||||||
use tauri_plugin_autostart::ManagerExt;
|
use tauri_plugin_autostart::ManagerExt;
|
||||||
|
|||||||
Reference in New Issue
Block a user