From c59c211c6cec27dbccfb575a438a799727726887 Mon Sep 17 00:00:00 2001 From: Petard Jonson <41122242+greenhat616@users.noreply.github.com> Date: Sat, 27 Jul 2024 02:30:44 +0800 Subject: [PATCH] fix: lint --- backend/tauri/src/core/clash/core.rs | 34 ++++++++++++---------------- backend/tauri/src/utils/dirs.rs | 16 ++++--------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/backend/tauri/src/core/clash/core.rs b/backend/tauri/src/core/clash/core.rs index 3c9789f80e..0fef62f9fc 100644 --- a/backend/tauri/src/core/clash/core.rs +++ b/backend/tauri/src/core/clash/core.rs @@ -5,7 +5,7 @@ use crate::{ log_err, utils::dirs, }; -use anyhow::{bail, Context, Result}; +use anyhow::{bail, Result}; use nyanpasu_ipc::{api::status::CoreState, utils::get_current_ts}; use nyanpasu_utils::{ core::{ @@ -18,8 +18,6 @@ use once_cell::sync::OnceCell; use parking_lot::Mutex; use std::{ borrow::Cow, - fs, - io::Write, path::PathBuf, sync::{ atomic::{AtomicBool, AtomicI64, Ordering}, @@ -27,8 +25,7 @@ use std::{ }, time::Duration, }; -use sysinfo::{Pid, System}; -use tauri::api::process::{Command, CommandChild}; +use tauri::api::process::Command; use tokio::time::sleep; pub enum RunType { @@ -179,19 +176,19 @@ impl Instance { err_buf.join("\n") )); tracing::error!("{}\n{}", err, err_buf.join("\n")); - if let Err(_) = tx.send(Err(err)).await { - if !kill_flag.load(Ordering::Relaxed) { - std::thread::spawn(move || { - block_on(async { - tracing::info!( - "Trying to recover core." - ); - let _ = CoreManager::global() - .recover_core() - .await; - }); + if tx.send(Err(err)).await.is_err() + && !kill_flag.load(Ordering::Relaxed) + { + std::thread::spawn(move || { + block_on(async { + tracing::info!( + "Trying to recover core." + ); + let _ = CoreManager::global() + .recover_core() + .await; }); - } + }); } } break; @@ -276,9 +273,6 @@ impl Instance { } } -#[cfg(target_os = "windows")] -use crate::core::win_service; - #[derive(Debug)] pub struct CoreManager { instance: Mutex>>, diff --git a/backend/tauri/src/utils/dirs.rs b/backend/tauri/src/utils/dirs.rs index 5c3c472955..ec89d63593 100644 --- a/backend/tauri/src/utils/dirs.rs +++ b/backend/tauri/src/utils/dirs.rs @@ -70,11 +70,7 @@ pub fn app_config_dir() -> Result { { if *PORTABLE_FLAG.get().unwrap_or(&false) { let app_dir = app_install_dir()?; - Some( - PathBuf::from(app_dir) - .join(".config") - .join(PREVIOUS_APP_NAME), - ) + Some(app_dir.join(".config").join(PREVIOUS_APP_NAME)) } else if let Ok(Some(path)) = super::winreg::get_app_dir() { Some(path) } else { @@ -106,7 +102,7 @@ pub fn app_data_dir() -> Result { { if *PORTABLE_FLAG.get().unwrap_or(&false) { let app_dir = app_install_dir()?; - Some(PathBuf::from(app_dir).join(".data").join(PREVIOUS_APP_NAME)) + Some(app_dir.join(".data").join(PREVIOUS_APP_NAME)) } else { None } @@ -140,9 +136,7 @@ pub fn old_app_home_dir() -> Result { .join(PREVIOUS_APP_NAME)) } else { let app_dir = app_install_dir()?; - Ok(PathBuf::from(app_dir) - .join(".config") - .join(PREVIOUS_APP_NAME)) + Ok(app_dir.join(".config").join(PREVIOUS_APP_NAME)) } } @@ -179,9 +173,7 @@ pub fn app_home_dir() -> Result { .join(".config") .join(APP_NAME)); } - Ok(PathBuf::from(app_install_dir()?) - .join(".config") - .join(APP_NAME)) + Ok((app_install_dir()?).join(".config").join(APP_NAME)) } #[cfg(not(target_os = "windows"))]