fix(clippy): clippy warning codes

This commit is contained in:
Tunglies
2025-03-28 11:43:21 +08:00
parent 1c046f3ca3
commit f6c0f144a6
4 changed files with 14 additions and 18 deletions

View File

@@ -1,22 +1,16 @@
use super::CmdResult; use super::CmdResult;
use crate::{ use crate::core::{service, CoreManager};
core::{service, CoreManager},
logging_error,
utils::logging::Type,
};
async fn execute_service_operation( async fn execute_service_operation(
service_op: impl std::future::Future<Output = Result<(), impl ToString + std::fmt::Debug>>, service_op: impl std::future::Future<Output = Result<(), impl ToString + std::fmt::Debug>>,
op_type: &str, op_type: &str,
) -> CmdResult { ) -> CmdResult {
if let Err(_) = service_op.await { if service_op.await.is_err() {
let emsg = format!("{} {} failed", op_type, "service"); let emsg = format!("{} {} failed", op_type, "service");
// logging_error!(Type::Service, true, "{:?}", e);
return Err(emsg); return Err(emsg);
} }
if let Err(_) = CoreManager::global().restart_core().await { if CoreManager::global().restart_core().await.is_err() {
let emsg = format!("{} {} failed", op_type, "core"); let emsg = format!("{} {} failed", op_type, "core");
// logging_error!(Type::Core, true, "{:?}", e);
return Err(emsg); return Err(emsg);
} }
Ok(()) Ok(())

View File

@@ -576,9 +576,11 @@ impl CoreManager {
// 安装失败记录错误并使用sidecar模式 // 安装失败记录错误并使用sidecar模式
logging!(warn, Type::Core, true, "服务安装失败: {}", err); logging!(warn, Type::Core, true, "服务安装失败: {}", err);
let mut new_state = service::ServiceState::default(); let new_state = service::ServiceState {
new_state.last_error = Some(err.to_string()); last_error: Some(err.to_string()),
new_state.prefer_sidecar = true; // 标记偏好sidecar模式 prefer_sidecar: true,
..Default::default()
};
new_state.save()?; new_state.save()?;
self.start_core_by_sidecar().await?; self.start_core_by_sidecar().await?;

View File

@@ -50,7 +50,7 @@ pub struct Tray {}
impl TrayState { impl TrayState {
pub fn get_common_tray_icon() -> (bool, Vec<u8>) { pub fn get_common_tray_icon() -> (bool, Vec<u8>) {
let verge = Config::verge().latest().clone(); let verge = Config::verge().latest().clone();
let is_common_tray_icon = verge.common_tray_icon.clone().unwrap_or(false); let is_common_tray_icon = verge.common_tray_icon.unwrap_or(false);
if is_common_tray_icon { if is_common_tray_icon {
if let Some(common_icon_path) = find_target_icons("common").unwrap() { if let Some(common_icon_path) = find_target_icons("common").unwrap() {
let icon_data = fs::read(common_icon_path).unwrap(); let icon_data = fs::read(common_icon_path).unwrap();
@@ -59,7 +59,7 @@ impl TrayState {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
let tray_icon_colorful = verge.tray_icon.clone().unwrap_or("monochrome".to_string()); let tray_icon_colorful = verge.tray_icon.unwrap_or("monochrome".to_string());
if tray_icon_colorful == "monochrome" { if tray_icon_colorful == "monochrome" {
( (
false, false,
@@ -84,7 +84,7 @@ impl TrayState {
pub fn get_sysproxy_tray_icon() -> (bool, Vec<u8>) { pub fn get_sysproxy_tray_icon() -> (bool, Vec<u8>) {
let verge = Config::verge().latest().clone(); let verge = Config::verge().latest().clone();
let is_sysproxy_tray_icon = verge.sysproxy_tray_icon.clone().unwrap_or(false); let is_sysproxy_tray_icon = verge.sysproxy_tray_icon.unwrap_or(false);
if is_sysproxy_tray_icon { if is_sysproxy_tray_icon {
if let Some(sysproxy_icon_path) = find_target_icons("sysproxy").unwrap() { if let Some(sysproxy_icon_path) = find_target_icons("sysproxy").unwrap() {
let icon_data = fs::read(sysproxy_icon_path).unwrap(); let icon_data = fs::read(sysproxy_icon_path).unwrap();
@@ -118,7 +118,7 @@ impl TrayState {
pub fn get_tun_tray_icon() -> (bool, Vec<u8>) { pub fn get_tun_tray_icon() -> (bool, Vec<u8>) {
let verge = Config::verge().latest().clone(); let verge = Config::verge().latest().clone();
let is_tun_tray_icon = verge.tun_tray_icon.clone().unwrap_or(false); let is_tun_tray_icon = verge.tun_tray_icon.unwrap_or(false);
if is_tun_tray_icon { if is_tun_tray_icon {
if let Some(tun_icon_path) = find_target_icons("tun").unwrap() { if let Some(tun_icon_path) = find_target_icons("tun").unwrap() {
let icon_data = fs::read(tun_icon_path).unwrap(); let icon_data = fs::read(tun_icon_path).unwrap();

View File

@@ -76,10 +76,10 @@ impl SpeedRate {
} }
// 分离图标加载和速率渲染 // 分离图标加载和速率渲染
pub fn add_speed_text<'a>( pub fn add_speed_text(
is_custom_icon: bool, is_custom_icon: bool,
icon_bytes: Option<Vec<u8>>, icon_bytes: Option<Vec<u8>>,
rate: Option<&'a Rate>, rate: Option<&Rate>,
) -> Result<Vec<u8>> { ) -> Result<Vec<u8>> {
let rate = rate.unwrap_or(&Rate { up: 0, down: 0 }); let rate = rate.unwrap_or(&Rate { up: 0, down: 0 });