fix: clippy errors with new config (#4428)

* refactor: improve code quality with clippy fixes and standardized logging

- Replace dangerous unwrap()/expect() calls with proper error handling
- Standardize logging from log:: to logging\! macro with Type:: classifications
- Fix app handle panics with graceful fallback patterns
- Improve error resilience across 35+ modules without breaking functionality
- Reduce clippy warnings from 300+ to 0 in main library code

* chore: update Cargo.toml configuration

* refactor: resolve all clippy warnings
- Fix Arc clone warnings using explicit Arc::clone syntax across 9 files
- Add #[allow(clippy::expect_used)] to test functions for appropriate expect usage
- Remove no-effect statements from debug code cleanup
- Apply clippy auto-fixes for dbg\! macro removals and path statements
- Achieve zero clippy warnings on all targets with -D warnings flag

* chore: update Cargo.toml clippy configuration

* refactor: simplify macOS job configuration and improve caching

* refactor: remove unnecessary async/await from service and proxy functions

* refactor: streamline pnpm installation in CI configuration

* refactor: simplify error handling and remove unnecessary else statements

* refactor: replace async/await with synchronous locks for core management

* refactor: add workflow_dispatch trigger to clippy job

* refactor: convert async functions to synchronous for service management

* refactor: convert async functions to synchronous for UWP tool invocation

* fix: change wrong logging

* refactor: convert proxy restoration functions to async

* Revert "refactor: convert proxy restoration functions to async"

This reverts commit b82f5d250b2af7151e4dfd7dd411630b34ed2c18.

* refactor: update proxy restoration functions to return Result types

* fix: handle errors during proxy restoration and update async function signatures

* fix: handle errors during proxy restoration and update async function signatures

* refactor: update restore_pac_proxy and restore_sys_proxy functions to async

* fix: convert restore_pac_proxy and restore_sys_proxy functions to async

* fix: await restore_sys_proxy calls in proxy restoration logic

* fix: suppress clippy warnings for unused async functions in proxy restoration

* fix: suppress clippy warnings for unused async functions in proxy restoration
This commit is contained in:
Tunglies
2025-08-18 02:02:25 +08:00
committed by GitHub
parent a5fdd3f1a2
commit 537d27d10b
49 changed files with 1275 additions and 923 deletions

View File

@@ -57,7 +57,9 @@ pub async fn restore_webdav_backup(filename: String) -> Result<()> {
let webdav_username = verge_data.webdav_username.clone();
let webdav_password = verge_data.webdav_password.clone();
let backup_storage_path = app_home_dir().unwrap().join(&filename);
let backup_storage_path = app_home_dir()
.map_err(|e| anyhow::anyhow!("Failed to get app home dir: {e}"))?
.join(&filename);
backup::WebDavClient::global()
.download(filename, backup_storage_path.clone())
.await

View File

@@ -2,7 +2,7 @@ use crate::{
config::Config,
core::{handle, tray, CoreManager},
ipc::IpcManager,
logging_error,
logging, logging_error,
process::AsyncHandler,
utils::{logging::Type, resolve},
};
@@ -30,8 +30,11 @@ pub fn restart_app() {
AsyncHandler::spawn(move || async move {
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
resolve::resolve_reset_async().await;
let app_handle = handle::Handle::global().app_handle().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
let Some(app_handle) = handle::Handle::global().app_handle() else {
logging!(error, Type::Core, "Failed to get app handle for restart");
return;
};
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tauri::process::restart(&app_handle.env());
});
}

View File

@@ -15,7 +15,7 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
let res = {
// 激活订阅
if patch.get("secret").is_some() || patch.get("external-controller").is_some() {
Config::generate().await?;
Config::generate()?;
CoreManager::global().restart_core().await?;
} else {
if patch.get("mode").is_some() {
@@ -173,7 +173,7 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
// Process updates based on flags
if (update_flags & (UpdateFlags::RestartCore as i32)) != 0 {
Config::generate().await?;
Config::generate()?;
CoreManager::global().restart_core().await?;
}
if (update_flags & (UpdateFlags::ClashConfig as i32)) != 0 {
@@ -191,7 +191,9 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
sysopt::Sysopt::global().update_sysproxy().await?;
}
if (update_flags & (UpdateFlags::Hotkey as i32)) != 0 {
hotkey::Hotkey::global().update(patch.hotkeys.unwrap())?;
if let Some(hotkeys) = patch.hotkeys {
hotkey::Hotkey::global().update(hotkeys)?;
}
}
if (update_flags & (UpdateFlags::SystrayMenu as i32)) != 0 {
tray::Tray::global().update_menu()?;
@@ -206,7 +208,7 @@ pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
tray::Tray::global().update_click_behavior()?;
}
if (update_flags & (UpdateFlags::LighteWeight as i32)) != 0 {
if enable_auto_light_weight.unwrap() {
if enable_auto_light_weight.unwrap_or(false) {
lightweight::enable_auto_light_weight_mode();
} else {
lightweight::disable_auto_light_weight_mode();

View File

@@ -11,7 +11,14 @@ use anyhow::{bail, Result};
/// Toggle proxy profile
pub fn toggle_proxy_profile(profile_index: String) {
AsyncHandler::spawn(|| async move {
let app_handle = handle::Handle::global().app_handle().unwrap();
let Some(app_handle) = handle::Handle::global().app_handle() else {
logging!(
error,
Type::Config,
"Failed to get app handle for profile toggle"
);
return;
};
match cmd::patch_profiles_config_by_profile_index(app_handle, profile_index).await {
Ok(_) => {
let _ = tray::Tray::global().update_menu();
@@ -50,9 +57,14 @@ pub async fn update_profile(
log::info!(target: "app",
"[订阅更新] {} 是远程订阅URL: {}",
uid,
item.url.clone().unwrap()
item.url.clone().ok_or_else(|| anyhow::anyhow!("Profile URL is None"))?
);
Some((item.url.clone().unwrap(), item.option.clone()))
Some((
item.url
.clone()
.ok_or_else(|| anyhow::anyhow!("Profile URL is None"))?,
item.option.clone(),
))
}
};
@@ -137,7 +149,13 @@ pub async fn update_profile(
logging!(info, Type::Config, true, "[订阅更新] 更新成功");
handle::Handle::refresh_clash();
if let Err(err) = cmd::proxy::force_refresh_proxies().await {
logging!(error, Type::Config, true, "[订阅更新] 代理组刷新失败: {}", err);
logging!(
error,
Type::Config,
true,
"[订阅更新] 代理组刷新失败: {}",
err
);
}
}
Err(err) => {

View File

@@ -2,7 +2,9 @@ use crate::{
config::{Config, IVerge},
core::handle,
ipc::IpcManager,
logging,
process::AsyncHandler,
utils::logging::Type,
};
use std::env;
use tauri_plugin_clipboard_manager::ClipboardExt;
@@ -71,7 +73,14 @@ pub fn copy_clash_env() {
.unwrap_or_else(|| "127.0.0.1".to_string())
});
let app_handle = handle::Handle::global().app_handle().unwrap();
let Some(app_handle) = handle::Handle::global().app_handle() else {
logging!(
error,
Type::System,
"Failed to get app handle for proxy operation"
);
return;
};
let port = {
Config::verge()
.latest_ref()

View File

@@ -67,7 +67,14 @@ pub fn quit() {
logging!(debug, Type::System, true, "启动退出流程");
// 获取应用句柄并设置退出标志
let app_handle = handle::Handle::global().app_handle().unwrap();
let Some(app_handle) = handle::Handle::global().app_handle() else {
logging!(
error,
Type::System,
"Failed to get app handle for quit operation"
);
return;
};
handle::Handle::global().set_is_exiting();
// 优先关闭窗口,提供立即反馈