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 crate::utils::{clash, import};
#[tauri::command]
pub fn cmd_restart_sidebar() {
kill_children();

View File

@ -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 {

View File

@ -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

View File

@ -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

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;
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};

View File

@ -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();

View File

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