refactor: wip

This commit is contained in:
GyDi
2022-11-14 01:26:33 +08:00
parent afc37c71a6
commit 837422fbb8
32 changed files with 2704 additions and 880 deletions

View File

@@ -1,4 +1,3 @@
use std::env::temp_dir;
use std::path::PathBuf;
use tauri::{
api::path::{home_dir, resource_dir},
@@ -13,7 +12,7 @@ static APP_DIR: &str = "clash-verge-dev";
static CLASH_CONFIG: &str = "config.yaml";
static VERGE_CONFIG: &str = "verge.yaml";
static PROFILE_YAML: &str = "profiles.yaml";
static PROFILE_TEMP: &str = "clash-verge-runtime.yaml";
static CLASH_RUNTIME_YAML: &str = "clash-verge-runtime.yaml";
static mut RESOURCE_DIR: Option<PathBuf> = None;
@@ -99,12 +98,8 @@ pub fn profiles_path() -> PathBuf {
app_home_dir().join(PROFILE_YAML)
}
pub fn profiles_temp_path() -> PathBuf {
#[cfg(not(feature = "debug-yml"))]
return temp_dir().join(PROFILE_TEMP);
#[cfg(feature = "debug-yml")]
return app_home_dir().join(PROFILE_TEMP);
pub fn clash_runtime_yaml() -> PathBuf {
app_home_dir().join(CLASH_RUNTIME_YAML)
}
pub fn clash_pid_path() -> PathBuf {
@@ -136,3 +131,11 @@ pub fn service_log_file() -> PathBuf {
log_file
}
pub fn path_to_str(path: &PathBuf) -> anyhow::Result<&str> {
let path_str = path
.as_os_str()
.to_str()
.ok_or(anyhow::anyhow!("failed to get path from {:?}", path))?;
Ok(path_str)
}