refactor: adjust dirs structure

This commit is contained in:
GyDi 2021-12-14 16:07:15 +08:00
parent db802e959d
commit 4719649bf4
9 changed files with 35 additions and 20 deletions

View File

@ -1,7 +1,7 @@
use crate::clash;
use crate::import;
use tauri::api::process::kill_children; use tauri::api::process::kill_children;
use crate::utils::{clash, import};
#[tauri::command] #[tauri::command]
pub fn cmd_restart_sidebar() { pub fn cmd_restart_sidebar() {
kill_children(); kill_children();

View File

@ -3,7 +3,7 @@ use serde_yaml::{Mapping, Value};
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use super::{profiles::ProfilesConfig, ClashController}; use super::{profiles::ProfilesConfig, ClashController};
use crate::init::app_home_dir; use crate::utils::app_home_dir;
/// read data from yaml as struct T /// read data from yaml as struct T
pub fn read_yaml<T: DeserializeOwned>(path: PathBuf) -> T { pub fn read_yaml<T: DeserializeOwned>(path: PathBuf) -> T {

View File

@ -5,12 +5,9 @@
extern crate tauri; extern crate tauri;
mod clash;
mod cmd; mod cmd;
mod config; mod config;
mod import; mod utils;
mod init;
mod sysopt;
use tauri::{ use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
@ -63,7 +60,7 @@ fn main() -> std::io::Result<()> {
.expect("error while running tauri application"); .expect("error while running tauri application");
// init app config // init app config
init::init_app(app.package_info()); utils::init::init_app(app.package_info());
// clash::run_clash_bin(); // clash::run_clash_bin();
// 通过clash config初始化menu和tray // 通过clash config初始化menu和tray

View File

@ -1,6 +1,6 @@
extern crate log; extern crate log;
use crate::init::app_home_dir; use crate::utils::app_home_dir;
use tauri::api::process::{Command, CommandEvent}; use tauri::api::process::{Command, CommandEvent};
/// Run the clash bin /// Run the clash bin

View 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")
}

View File

@ -1,7 +1,7 @@
extern crate reqwest; extern crate reqwest;
use crate::config::{read_profiles, save_profiles, ProfileExtra, ProfileItem}; 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::fs::File;
use std::io::Write; use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};

View File

@ -7,18 +7,11 @@ use log4rs::config::{Appender, Config, Root};
use log4rs::encode::pattern::PatternEncoder; use log4rs::encode::pattern::PatternEncoder;
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tauri::api::path::{home_dir, resource_dir};
use tauri::PackageInfo; use tauri::PackageInfo;
/// get the verge app home dir use crate::utils::{app_home_dir, app_resources_dir};
pub fn app_home_dir() -> PathBuf {
home_dir()
.unwrap()
.join(Path::new(".config"))
.join(Path::new("clash-verge"))
}
/// initialize this instance's log file /// initialize this instance's log file
fn init_log(log_dir: &PathBuf) { 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 log_dir = app_dir.join("logs");
let profiles_dir = app_dir.join("profiles"); 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() { if !app_dir.exists() {
fs::create_dir(&app_dir).unwrap(); fs::create_dir(&app_dir).unwrap();

View File

@ -0,0 +1,7 @@
mod dirs;
pub use self::dirs::*;
pub mod clash;
pub mod import;
pub mod init;
pub mod sysopt;