Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 26, 2024
1 parent e3e9fee commit c59c211
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
34 changes: 14 additions & 20 deletions backend/tauri/src/core/clash/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -18,17 +18,14 @@ use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use std::{
borrow::Cow,
fs,
io::Write,
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicI64, Ordering},
Arc,
},
time::Duration,
};
use sysinfo::{Pid, System};
use tauri::api::process::{Command, CommandChild};
use tauri::api::process::Command;
use tokio::time::sleep;

pub enum RunType {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -276,9 +273,6 @@ impl Instance {
}
}

#[cfg(target_os = "windows")]
use crate::core::win_service;

#[derive(Debug)]
pub struct CoreManager {
instance: Mutex<Option<Arc<Instance>>>,
Expand Down
16 changes: 4 additions & 12 deletions backend/tauri/src/utils/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ pub fn app_config_dir() -> Result<PathBuf> {
{
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 {
Expand Down Expand Up @@ -106,7 +102,7 @@ pub fn app_data_dir() -> Result<PathBuf> {
{
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
}
Expand Down Expand Up @@ -140,9 +136,7 @@ pub fn old_app_home_dir() -> Result<PathBuf> {
.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))
}
}

Expand Down Expand Up @@ -179,9 +173,7 @@ pub fn app_home_dir() -> Result<PathBuf> {
.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"))]
Expand Down

0 comments on commit c59c211

Please sign in to comment.