refactor: adjust dirs structure
This commit is contained in:
parent
db802e959d
commit
4719649bf4
@ -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();
|
||||
|
@ -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<T: DeserializeOwned>(path: PathBuf) -> T {
|
||||
|
@ -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
|
||||
|
@ -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
|
18
src-tauri/src/utils/dirs.rs
Normal file
18
src-tauri/src/utils/dirs.rs
Normal file
@ -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")
|
||||
}
|
@ -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};
|
@ -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();
|
7
src-tauri/src/utils/mod.rs
Normal file
7
src-tauri/src/utils/mod.rs
Normal file
@ -0,0 +1,7 @@
|
||||
mod dirs;
|
||||
pub use self::dirs::*;
|
||||
|
||||
pub mod clash;
|
||||
pub mod import;
|
||||
pub mod init;
|
||||
pub mod sysopt;
|
Loading…
Reference in New Issue
Block a user