mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 04:43:44 +08:00
parent
a036597f5f
commit
c5855119d8
@ -15,6 +15,7 @@ static VERGE_CONFIG: &str = "verge.yaml";
|
|||||||
static PROFILE_YAML: &str = "profiles.yaml";
|
static PROFILE_YAML: &str = "profiles.yaml";
|
||||||
|
|
||||||
static mut RESOURCE_DIR: Option<PathBuf> = None;
|
static mut RESOURCE_DIR: Option<PathBuf> = None;
|
||||||
|
static mut APP_HOME_DIR: Option<PathBuf> = None;
|
||||||
|
|
||||||
/// portable flag
|
/// portable flag
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
@ -42,28 +43,27 @@ pub unsafe fn init_portable_flag() -> Result<()> {
|
|||||||
|
|
||||||
/// get the verge app home dir
|
/// get the verge app home dir
|
||||||
pub fn app_home_dir() -> Result<PathBuf> {
|
pub fn app_home_dir() -> Result<PathBuf> {
|
||||||
#[cfg(target_os = "windows")]
|
use tauri::utils::platform::current_exe;
|
||||||
unsafe {
|
let app_exe = current_exe()?;
|
||||||
use tauri::utils::platform::current_exe;
|
let app_exe = dunce::canonicalize(app_exe)?;
|
||||||
|
let app_dir = app_exe
|
||||||
|
.parent()
|
||||||
|
.ok_or(anyhow::anyhow!("failed to get the portable app dir"))?;
|
||||||
|
|
||||||
if !PORTABLE_FLAG {
|
let portable_home_dir = PathBuf::from(app_dir).join(".config").join(APP_ID);
|
||||||
Ok(data_dir()
|
let home_dir = data_dir()
|
||||||
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
|
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
|
||||||
.join(APP_ID))
|
.join(APP_ID);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
if PORTABLE_FLAG {
|
||||||
|
APP_HOME_DIR = Some(portable_home_dir.clone());
|
||||||
|
Ok(portable_home_dir)
|
||||||
} else {
|
} else {
|
||||||
let app_exe = current_exe()?;
|
APP_HOME_DIR = Some(home_dir.clone());
|
||||||
let app_exe = dunce::canonicalize(app_exe)?;
|
Ok(home_dir)
|
||||||
let app_dir = app_exe
|
|
||||||
.parent()
|
|
||||||
.ok_or(anyhow::anyhow!("failed to get the portable app dir"))?;
|
|
||||||
Ok(PathBuf::from(app_dir).join(".config").join(APP_ID))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
Ok(data_dir()
|
|
||||||
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
|
|
||||||
.join(APP_ID))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the resources dir
|
/// get the resources dir
|
||||||
@ -116,9 +116,9 @@ pub fn app_res_dir() -> Result<PathBuf> {
|
|||||||
|
|
||||||
pub fn clash_pid_path() -> Result<PathBuf> {
|
pub fn clash_pid_path() -> Result<PathBuf> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Ok(RESOURCE_DIR
|
Ok(APP_HOME_DIR
|
||||||
.clone()
|
.clone()
|
||||||
.ok_or(anyhow::anyhow!("failed to get the resource dir"))?
|
.ok_or(anyhow::anyhow!("failed to get the app home dir"))?
|
||||||
.join("clash.pid"))
|
.join("clash.pid"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user