diff --git a/src-tauri/src/core/async_proxy_query.rs b/src-tauri/src/core/async_proxy_query.rs index a8279044..b26a4951 100644 --- a/src-tauri/src/core/async_proxy_query.rs +++ b/src-tauri/src/core/async_proxy_query.rs @@ -1,3 +1,5 @@ +#[cfg(target_os = "linux")] +use anyhow::anyhow; use anyhow::Result; use serde::{Deserialize, Serialize}; use tokio::process::Command; @@ -71,7 +73,7 @@ impl AsyncProxyQuery { async fn get_auto_proxy_impl() -> Result { // Windows: 使用 netsh winhttp show proxy 命令 let output = Command::new("netsh") - .args(&["winhttp", "show", "proxy"]) + .args(["winhttp", "show", "proxy"]) .output() .await?; @@ -172,7 +174,7 @@ impl AsyncProxyQuery { // 尝试使用 gsettings 获取 GNOME 代理设置 let output = Command::new("gsettings") - .args(&["get", "org.gnome.system.proxy", "mode"]) + .args(["get", "org.gnome.system.proxy", "mode"]) .output() .await; @@ -182,7 +184,7 @@ impl AsyncProxyQuery { if mode.contains("auto") { // 获取 PAC URL let pac_output = Command::new("gsettings") - .args(&["get", "org.gnome.system.proxy", "autoconfig-url"]) + .args(["get", "org.gnome.system.proxy", "autoconfig-url"]) .output() .await; @@ -212,7 +214,7 @@ impl AsyncProxyQuery { #[cfg(target_os = "windows")] async fn get_system_proxy_impl() -> Result { let output = Command::new("netsh") - .args(&["winhttp", "show", "proxy"]) + .args(["winhttp", "show", "proxy"]) .output() .await?; @@ -333,7 +335,7 @@ impl AsyncProxyQuery { // 尝试使用 gsettings 获取 GNOME 代理设置 let mode_output = Command::new("gsettings") - .args(&["get", "org.gnome.system.proxy", "mode"]) + .args(["get", "org.gnome.system.proxy", "mode"]) .output() .await; @@ -345,12 +347,12 @@ impl AsyncProxyQuery { if mode.contains("manual") { // 获取HTTP代理设置 let host_result = Command::new("gsettings") - .args(&["get", "org.gnome.system.proxy.http", "host"]) + .args(["get", "org.gnome.system.proxy.http", "host"]) .output() .await; let port_result = Command::new("gsettings") - .args(&["get", "org.gnome.system.proxy.http", "port"]) + .args(["get", "org.gnome.system.proxy.http", "port"]) .output() .await; @@ -390,10 +392,10 @@ impl AsyncProxyQuery { let url = proxy_url.trim(); // 移除协议前缀 - let url = if url.starts_with("http://") { - &url[7..] - } else if url.starts_with("https://") { - &url[8..] + let url = if let Some(stripped) = url.strip_prefix("http://") { + stripped + } else if let Some(stripped) = url.strip_prefix("https://") { + stripped } else { url }; diff --git a/src-tauri/src/core/event_driven_proxy.rs b/src-tauri/src/core/event_driven_proxy.rs index 97cd2853..6813dd1e 100644 --- a/src-tauri/src/core/event_driven_proxy.rs +++ b/src-tauri/src/core/event_driven_proxy.rs @@ -530,9 +530,9 @@ impl EventDrivenProxyManager { use tauri_plugin_shell::ShellExt; let app_handle = match Handle::global().app_handle() { - Ok(handle) => handle, - Err(e) => { - log::error!(target: "app", "获取应用句柄失败: {}", e); + Some(handle) => handle, + None => { + log::error!(target: "app", "获取应用句柄失败"); return; } }; diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index 71cca516..4cca93f3 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -9,6 +9,7 @@ use crate::{ use anyhow::Result; use once_cell::sync::OnceCell; use std::sync::Arc; +#[cfg(not(target_os = "windows"))] use sysproxy::{Autoproxy, Sysproxy}; use tauri::async_runtime::Mutex as TokioMutex; use tauri_plugin_autostart::ManagerExt;