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

@@ -112,7 +112,7 @@ pub struct JsonResponse {
}
#[cfg(target_os = "windows")]
pub async fn uninstall_service() -> Result<()> {
pub fn uninstall_service() -> Result<()> {
logging!(info, Type::Service, true, "uninstall service");
use deelevate::{PrivilegeLevel, Token};
@@ -138,7 +138,7 @@ pub async fn uninstall_service() -> Result<()> {
if !status.success() {
bail!(
"failed to uninstall service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -146,7 +146,7 @@ pub async fn uninstall_service() -> Result<()> {
}
#[cfg(target_os = "windows")]
pub async fn install_service() -> Result<()> {
pub fn install_service() -> Result<()> {
logging!(info, Type::Service, true, "install service");
use deelevate::{PrivilegeLevel, Token};
@@ -172,7 +172,7 @@ pub async fn install_service() -> Result<()> {
if !status.success() {
bail!(
"failed to install service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -180,7 +180,7 @@ pub async fn install_service() -> Result<()> {
}
#[cfg(target_os = "windows")]
pub async fn reinstall_service() -> Result<()> {
pub fn reinstall_service() -> Result<()> {
logging!(info, Type::Service, true, "reinstall service");
// 获取当前服务状态
@@ -198,7 +198,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 先卸载服务
if let Err(err) = uninstall_service().await {
if let Err(err) = uninstall_service() {
logging!(
warn,
Type::Service,
@@ -209,7 +209,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 再安装服务
match install_service().await {
match install_service() {
Ok(_) => {
// 记录安装信息并保存
service_state.record_install();
@@ -228,7 +228,7 @@ pub async fn reinstall_service() -> Result<()> {
}
#[cfg(target_os = "linux")]
pub async fn uninstall_service() -> Result<()> {
pub fn uninstall_service() -> Result<()> {
logging!(info, Type::Service, true, "uninstall service");
use users::get_effective_uid;
@@ -254,13 +254,13 @@ pub async fn uninstall_service() -> Result<()> {
Type::Service,
true,
"uninstall status code:{}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
if !status.success() {
bail!(
"failed to uninstall service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -268,7 +268,7 @@ pub async fn uninstall_service() -> Result<()> {
}
#[cfg(target_os = "linux")]
pub async fn install_service() -> Result<()> {
pub fn install_service() -> Result<()> {
logging!(info, Type::Service, true, "install service");
use users::get_effective_uid;
@@ -294,13 +294,13 @@ pub async fn install_service() -> Result<()> {
Type::Service,
true,
"install status code:{}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
if !status.success() {
bail!(
"failed to install service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -308,7 +308,7 @@ pub async fn install_service() -> Result<()> {
}
#[cfg(target_os = "linux")]
pub async fn reinstall_service() -> Result<()> {
pub fn reinstall_service() -> Result<()> {
logging!(info, Type::Service, true, "reinstall service");
// 获取当前服务状态
@@ -326,7 +326,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 先卸载服务
if let Err(err) = uninstall_service().await {
if let Err(err) = uninstall_service() {
logging!(
warn,
Type::Service,
@@ -337,7 +337,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 再安装服务
match install_service().await {
match install_service() {
Ok(_) => {
// 记录安装信息并保存
service_state.record_install();
@@ -356,7 +356,7 @@ pub async fn reinstall_service() -> Result<()> {
}
#[cfg(target_os = "macos")]
pub async fn uninstall_service() -> Result<()> {
pub fn uninstall_service() -> Result<()> {
use crate::utils::i18n::t;
logging!(info, Type::Service, true, "uninstall service");
@@ -384,7 +384,7 @@ pub async fn uninstall_service() -> Result<()> {
if !status.success() {
bail!(
"failed to uninstall service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -392,7 +392,7 @@ pub async fn uninstall_service() -> Result<()> {
}
#[cfg(target_os = "macos")]
pub async fn install_service() -> Result<()> {
pub fn install_service() -> Result<()> {
use crate::utils::i18n::t;
logging!(info, Type::Service, true, "install service");
@@ -420,7 +420,7 @@ pub async fn install_service() -> Result<()> {
if !status.success() {
bail!(
"failed to install service with status {}",
status.code().unwrap()
status.code().unwrap_or(-1)
);
}
@@ -428,7 +428,7 @@ pub async fn install_service() -> Result<()> {
}
#[cfg(target_os = "macos")]
pub async fn reinstall_service() -> Result<()> {
pub fn reinstall_service() -> Result<()> {
logging!(info, Type::Service, true, "reinstall service");
// 获取当前服务状态
@@ -446,7 +446,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 先卸载服务
if let Err(err) = uninstall_service().await {
if let Err(err) = uninstall_service() {
logging!(
warn,
Type::Service,
@@ -457,7 +457,7 @@ pub async fn reinstall_service() -> Result<()> {
}
// 再安装服务
match install_service().await {
match install_service() {
Ok(_) => {
// 记录安装信息并保存
service_state.record_install();
@@ -856,17 +856,14 @@ pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
if let Ok(()) = start_with_existing_service(config_file).await {
log::info!(target: "app", "尽管版本不匹配,但成功启动了服务");
return Ok(());
} else {
bail!("服务版本不匹配且无法重装,启动失败");
}
bail!("服务版本不匹配且无法重装,启动失败");
}
log::info!(target: "app", "开始重装服务");
if let Err(err) = reinstall_service().await {
if let Err(err) = reinstall_service() {
log::warn!(target: "app", "服务重装失败: {err}");
log::info!(target: "app", "尝试使用现有服务");
return start_with_existing_service(config_file).await;
bail!("Failed to reinstall service: {}", err);
}
log::info!(target: "app", "服务重装成功,尝试启动");
@@ -890,7 +887,7 @@ pub(super) async fn run_core_by_service(config_file: &PathBuf) -> Result<()> {
if check_service_needs_reinstall().await {
log::info!(target: "app", "服务需要重装");
if let Err(err) = reinstall_service().await {
if let Err(err) = reinstall_service() {
log::warn!(target: "app", "服务重装失败: {err}");
bail!("Failed to reinstall service: {}", err);
}
@@ -970,7 +967,7 @@ pub async fn is_service_available() -> Result<()> {
}
/// 强制重装服务UI修复按钮
pub async fn force_reinstall_service() -> Result<()> {
pub fn force_reinstall_service() -> Result<()> {
log::info!(target: "app", "用户请求强制重装服务");
let service_state = ServiceState::default();
@@ -978,7 +975,7 @@ pub async fn force_reinstall_service() -> Result<()> {
log::info!(target: "app", "已重置服务状态,开始执行重装");
match reinstall_service().await {
match reinstall_service() {
Ok(()) => {
log::info!(target: "app", "服务重装成功");
Ok(())