diff --git a/src-tauri/src/cmd.rs b/src-tauri/src/cmd.rs index 7994fb4..12aee41 100644 --- a/src-tauri/src/cmd.rs +++ b/src-tauri/src/cmd.rs @@ -1,7 +1,7 @@ -use crate::clash; -use crate::import; use tauri::api::process::kill_children; +use crate::utils::{clash, import}; + #[tauri::command] pub fn cmd_restart_sidebar() { kill_children(); diff --git a/src-tauri/src/config/operate.rs b/src-tauri/src/config/operate.rs index 1048eec..b5c944f 100644 --- a/src-tauri/src/config/operate.rs +++ b/src-tauri/src/config/operate.rs @@ -3,7 +3,7 @@ use serde_yaml::{Mapping, Value}; use std::{fs, path::PathBuf}; use super::{profiles::ProfilesConfig, ClashController}; -use crate::init::app_home_dir; +use crate::utils::app_home_dir; /// read data from yaml as struct T pub fn read_yaml(path: PathBuf) -> T { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index eb8a69d..742cf33 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -5,12 +5,9 @@ extern crate tauri; -mod clash; mod cmd; mod config; -mod import; -mod init; -mod sysopt; +mod utils; use tauri::{ CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, @@ -63,7 +60,7 @@ fn main() -> std::io::Result<()> { .expect("error while running tauri application"); // init app config - init::init_app(app.package_info()); + utils::init::init_app(app.package_info()); // clash::run_clash_bin(); // 通过clash config初始化menu和tray diff --git a/src-tauri/src/clash.rs b/src-tauri/src/utils/clash.rs similarity index 95% rename from src-tauri/src/clash.rs rename to src-tauri/src/utils/clash.rs index c727ffd..d028b79 100644 --- a/src-tauri/src/clash.rs +++ b/src-tauri/src/utils/clash.rs @@ -1,6 +1,6 @@ extern crate log; -use crate::init::app_home_dir; +use crate::utils::app_home_dir; use tauri::api::process::{Command, CommandEvent}; /// Run the clash bin diff --git a/src-tauri/src/utils/dirs.rs b/src-tauri/src/utils/dirs.rs new file mode 100644 index 0000000..5167472 --- /dev/null +++ b/src-tauri/src/utils/dirs.rs @@ -0,0 +1,18 @@ +use std::path::{Path, PathBuf}; +use tauri::{ + api::path::{home_dir, resource_dir}, + PackageInfo, +}; + +/// get the verge app home dir +pub fn app_home_dir() -> PathBuf { + home_dir() + .unwrap() + .join(Path::new(".config")) + .join(Path::new("clash-verge")) +} + +/// get the resources dir +pub fn app_resources_dir(package_info: &PackageInfo) -> PathBuf { + resource_dir(package_info).unwrap().join("resources") +} diff --git a/src-tauri/src/import.rs b/src-tauri/src/utils/import.rs similarity index 99% rename from src-tauri/src/import.rs rename to src-tauri/src/utils/import.rs index 1471bee..19311f5 100644 --- a/src-tauri/src/import.rs +++ b/src-tauri/src/utils/import.rs @@ -1,7 +1,7 @@ extern crate reqwest; use crate::config::{read_profiles, save_profiles, ProfileExtra, ProfileItem}; -use crate::init::app_home_dir; +use crate::utils::app_home_dir; use std::fs::File; use std::io::Write; use std::time::{SystemTime, UNIX_EPOCH}; diff --git a/src-tauri/src/init.rs b/src-tauri/src/utils/init.rs similarity index 90% rename from src-tauri/src/init.rs rename to src-tauri/src/utils/init.rs index f6abd9c..519435c 100644 --- a/src-tauri/src/init.rs +++ b/src-tauri/src/utils/init.rs @@ -7,18 +7,11 @@ use log4rs::config::{Appender, Config, Root}; use log4rs::encode::pattern::PatternEncoder; use std::fs; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::time::{SystemTime, UNIX_EPOCH}; -use tauri::api::path::{home_dir, resource_dir}; use tauri::PackageInfo; -/// get the verge app home dir -pub fn app_home_dir() -> PathBuf { - home_dir() - .unwrap() - .join(Path::new(".config")) - .join(Path::new("clash-verge")) -} +use crate::utils::{app_home_dir, app_resources_dir}; /// initialize this instance's log file fn init_log(log_dir: &PathBuf) { @@ -96,7 +89,7 @@ pub fn init_app(package_info: &PackageInfo) { let log_dir = app_dir.join("logs"); let profiles_dir = app_dir.join("profiles"); - let res_dir = resource_dir(package_info).unwrap().join("resources"); + let res_dir = app_resources_dir(package_info); if !app_dir.exists() { fs::create_dir(&app_dir).unwrap(); diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs new file mode 100644 index 0000000..064253f --- /dev/null +++ b/src-tauri/src/utils/mod.rs @@ -0,0 +1,7 @@ +mod dirs; +pub use self::dirs::*; + +pub mod clash; +pub mod import; +pub mod init; +pub mod sysopt; diff --git a/src-tauri/src/sysopt.rs b/src-tauri/src/utils/sysopt.rs similarity index 100% rename from src-tauri/src/sysopt.rs rename to src-tauri/src/utils/sysopt.rs