diff --git a/src-tauri/src/cmd/network.rs b/src-tauri/src/cmd/network.rs index b9ccb466..7b7e469d 100644 --- a/src-tauri/src/cmd/network.rs +++ b/src-tauri/src/cmd/network.rs @@ -8,7 +8,7 @@ use tokio::task::spawn_blocking; /// get the system proxy #[tauri::command] pub async fn get_sys_proxy() -> CmdResult { - let current = spawn_blocking(move || Sysproxy::get_system_proxy()) + let current = spawn_blocking(Sysproxy::get_system_proxy) .await .map_err(|e| format!("Failed to spawn blocking task for sysproxy: {}", e))? .map_err(|e| format!("Failed to get system proxy: {}", e))?; @@ -27,7 +27,7 @@ pub async fn get_sys_proxy() -> CmdResult { /// get the system proxy #[tauri::command] pub async fn get_auto_proxy() -> CmdResult { - let current = spawn_blocking(move || Autoproxy::get_auto_proxy()) + let current = spawn_blocking(Autoproxy::get_auto_proxy) .await .map_err(|e| format!("Failed to spawn blocking task for autoproxy: {}", e))? .map_err(|e| format!("Failed to get auto proxy: {}", e))?; diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index a900256e..76a86a8f 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -259,11 +259,11 @@ impl PrfItem { // 选择代理类型 let proxy_type = if self_proxy { - ProxyType::SelfProxy + ProxyType::Localhost } else if with_proxy { - ProxyType::SystemProxy + ProxyType::System } else { - ProxyType::NoProxy + ProxyType::None }; // 使用网络管理器发送请求 diff --git a/src-tauri/src/core/backup.rs b/src-tauri/src/core/backup.rs index d6b080ff..8f50e3e7 100644 --- a/src-tauri/src/core/backup.rs +++ b/src-tauri/src/core/backup.rs @@ -128,9 +128,10 @@ impl WebDavClient { .build()?; // 尝试检查目录是否存在,如果不存在尝试创建,但创建失败不报错 - if let Err(_) = client + if client .list(dirs::BACKUP_DIR, reqwest_dav::Depth::Number(0)) .await + .is_err() { let _ = client.mkcol(dirs::BACKUP_DIR).await; } diff --git a/src-tauri/src/core/handle.rs b/src-tauri/src/core/handle.rs index e36d9290..0bf3dd1a 100644 --- a/src-tauri/src/core/handle.rs +++ b/src-tauri/src/core/handle.rs @@ -89,7 +89,7 @@ impl NotificationSystem { let system_guard = handle.notification_system.read(); let is_emergency = system_guard .as_ref() - .and_then(|sys| Some(*sys.emergency_mode.read())) + .map(|sys| *sys.emergency_mode.read()) .unwrap_or(false); if is_emergency { @@ -110,7 +110,7 @@ impl NotificationSystem { &window, "verge://refresh-clash-config", "yes", - &handle, + handle, ); } FrontendEvent::RefreshVerge => { @@ -118,7 +118,7 @@ impl NotificationSystem { &window, "verge://refresh-verge-config", "yes", - &handle, + handle, ); } FrontendEvent::NoticeMessage { @@ -129,7 +129,7 @@ impl NotificationSystem { &window, "verge://notice-message", (status.clone(), message.clone()), - &handle, + handle, ); } } @@ -273,7 +273,7 @@ impl Default for Handle { impl Handle { pub fn global() -> &'static Handle { static HANDLE: OnceCell = OnceCell::new(); - HANDLE.get_or_init(|| Handle::default()) + HANDLE.get_or_init(Handle::default) } pub fn init(&self, app_handle: &AppHandle) { diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index d19d89c9..d65463d8 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -538,7 +538,7 @@ pub async fn check_ipc_service_status() -> Result { json_response.msg, json_response.data.is_some() ); - return Ok(json_response); + Ok(json_response) } else { // 尝试直接解析 match serde_json::from_value::(data.clone()) { @@ -551,7 +551,7 @@ pub async fn check_ipc_service_status() -> Result { json_response.code, json_response.msg ); - return Ok(json_response); + Ok(json_response) } Err(e) => { logging!( diff --git a/src-tauri/src/core/timer.rs b/src-tauri/src/core/timer.rs index 7950ee5c..5d0ab0ef 100644 --- a/src-tauri/src/core/timer.rs +++ b/src-tauri/src/core/timer.rs @@ -385,10 +385,7 @@ impl Timer { } }; - let profile = match items - .iter() - .find(|item| item.uid.as_ref().map(|u| u.as_str()) == Some(uid)) - { + let profile = match items.iter().find(|item| item.uid.as_deref() == Some(uid)) { Some(p) => p, None => { logging!(warn, Type::Timer, "找不到对应的配置,uid={}", uid); @@ -441,7 +438,6 @@ impl Timer { } /// Async task with better error handling and logging - async fn async_task(uid: String) { let task_start = std::time::Instant::now(); logging!(info, Type::Timer, "Running timer task for profile: {}", uid); diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 2d08d7d1..13ad92f6 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -442,7 +442,7 @@ impl Tray { traffic_result = stream.next() => { match traffic_result { Some(Ok(traffic)) => { - if let Ok(speedrate_result) = tokio::time::timeout( + if let Ok(Some(rate)) = tokio::time::timeout( std::time::Duration::from_millis(50), async { let guard = speed_rate.try_lock(); @@ -457,12 +457,10 @@ impl Tray { } } ).await { - if let Some(rate) = speedrate_result { - let _ = tokio::time::timeout( - std::time::Duration::from_millis(100), - async { let _ = Tray::global().update_icon(Some(rate)); } - ).await; - } + let _ = tokio::time::timeout( + std::time::Duration::from_millis(100), + async { let _ = Tray::global().update_icon(Some(rate)); } + ).await; } }, Some(Err(e)) => { diff --git a/src-tauri/src/core/tray/speed_rate.rs b/src-tauri/src/core/tray/speed_rate.rs index 000ffceb..06cbf610 100644 --- a/src-tauri/src/core/tray/speed_rate.rs +++ b/src-tauri/src/core/tray/speed_rate.rs @@ -271,7 +271,7 @@ impl Traffic { // 设置流超时控制 let traffic_stream = ws_stream .take_while(|msg| { - let continue_stream = matches!(msg, Ok(_)); + let continue_stream = msg.is_ok(); async move { continue_stream }.boxed() }) .filter_map(|msg| async move { diff --git a/src-tauri/src/feat/clash.rs b/src-tauri/src/feat/clash.rs index 55b9b87c..68b0134f 100644 --- a/src-tauri/src/feat/clash.rs +++ b/src-tauri/src/feat/clash.rs @@ -98,9 +98,9 @@ pub async fn test_delay(url: String) -> anyhow::Result { // 如果是TUN模式,不使用代理,否则使用自身代理 let proxy_type = if !tun_mode { - ProxyType::SelfProxy + ProxyType::Localhost } else { - ProxyType::NoProxy + ProxyType::None }; let user_agent = Some("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0".to_string()); diff --git a/src-tauri/src/utils/logging.rs b/src-tauri/src/utils/logging.rs index aff7849e..ec07ef9f 100644 --- a/src-tauri/src/utils/logging.rs +++ b/src-tauri/src/utils/logging.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, write}; +use std::fmt; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Type { diff --git a/src-tauri/src/utils/network.rs b/src-tauri/src/utils/network.rs index f5b99ff7..5ec90460 100644 --- a/src-tauri/src/utils/network.rs +++ b/src-tauri/src/utils/network.rs @@ -274,10 +274,10 @@ impl NetworkManager { } match proxy_type { - ProxyType::NoProxy => { + ProxyType::None => { builder = builder.no_proxy(); } - ProxyType::SelfProxy => { + ProxyType::Localhost => { let port = Config::verge() .latest() .verge_mixed_port @@ -295,7 +295,7 @@ impl NetworkManager { builder = builder.proxy(proxy); } } - ProxyType::SystemProxy => { + ProxyType::System => { use sysproxy::Sysproxy; if let Ok(p @ Sysproxy { enable: true, .. }) = Sysproxy::get_system_proxy() { @@ -420,7 +420,7 @@ impl NetworkManager { /// 代理类型 #[derive(Debug, Clone, Copy)] pub enum ProxyType { - NoProxy, - SelfProxy, - SystemProxy, + None, + Localhost, + System, }