refactor: retire application portable mode

This commit is contained in:
Tunglies
2026-09-06 20:53:36 +08:00
parent 9c9b7c3992
commit dd7b032cb1
5 changed files with 7 additions and 67 deletions
Generated
+1
View File
@@ -1128,6 +1128,7 @@ dependencies = [
"criterion",
"dark-light",
"deelevate",
"dirs 6.0.0",
"dunce",
"flate2",
"flexi_logger",
+1
View File
@@ -61,6 +61,7 @@ socket2 = { workspace = true }
warp = { version = "0.4.3", features = ["server"] }
open = "5.4.1"
rfd = { version = "0.16.0", default-features = false, features = ["common-controls-v6"] }
dirs = "6"
dunce = "1.0.5"
nanoid = "0.5"
chrono = { workspace = true }
-6
View File
@@ -395,12 +395,6 @@ impl SilentUpdater {
impl SilentUpdater {
async fn check_and_download(&self, app_handle: &tauri::AppHandle) -> Result<()> {
let is_portable = *dirs::PORTABLE_FLAG.get().unwrap_or(&false);
if is_portable {
logging!(debug, Type::System, "Silent update skipped: portable build");
return Ok(());
}
let auto_check = Config::verge().await.latest_arc().auto_check_update.unwrap_or(true);
if !auto_check {
logging!(debug, Type::System, "Silent update skipped: auto_check_update is false");
-2
View File
@@ -231,8 +231,6 @@ pub fn run() -> std::process::ExitCode {
return std::process::ExitCode::SUCCESS;
}
let _ = utils::dirs::init_portable_flag();
// Runs before the singleton check, which is the first thing to open a file in that directory.
#[cfg(windows)]
if let Err(error) =
+5 -59
View File
@@ -2,7 +2,6 @@ use crate::core::{CoreManager, handle, manager::RunningMode};
use anyhow::Result;
use async_trait::async_trait;
use clash_verge_logging::{Type, logging};
use once_cell::sync::OnceCell;
use std::{
fs,
path::{Path, PathBuf},
@@ -19,74 +18,21 @@ pub static APP_ID: &str = "io.github.clash-verge-rev.clash-verge-rev.dev";
#[cfg(feature = "verge-dev")]
pub static BACKUP_DIR: &str = "clash-verge-rev-backup-dev";
pub static PORTABLE_FLAG: OnceCell<bool> = OnceCell::new();
pub static CLASH_CONFIG: &str = "config.yaml";
pub static VERGE_CONFIG: &str = "verge.yaml";
pub static PROFILE_YAML: &str = "profiles.yaml";
/// Marks that the one-shot raise of too-short auto-update intervals has already run.
pub static UPDATE_INTERVAL_MIGRATED: &str = ".update-interval-migrated";
pub fn init_portable_flag() -> Result<()> {
use tauri::utils::platform::current_exe;
let app_exe = current_exe()?;
if let Some(dir) = app_exe.parent() {
let dir = PathBuf::from(dir).join(".config/PORTABLE");
if dir.exists() {
PORTABLE_FLAG.get_or_init(|| true);
}
}
PORTABLE_FLAG.get_or_init(|| false);
Ok(())
}
/// Uses the same platform data resolver as Tauri, including before its handle exists.
pub fn app_home_dir() -> Result<PathBuf> {
use tauri::utils::platform::current_exe;
let flag = PORTABLE_FLAG.get().unwrap_or(&false);
if *flag {
let app_exe = current_exe()?;
let app_exe = dunce::canonicalize(app_exe)?;
let app_dir = app_exe
.parent()
.ok_or_else(|| anyhow::anyhow!("failed to get the portable app dir"))?;
return Ok(PathBuf::from(app_dir).join(".config").join(APP_ID));
}
// Directory helpers can run before the Tauri handle is initialized.
let app_handle = handle::Handle::app_handle();
match app_handle.path().data_dir() {
Ok(dir) => Ok(dir.join(APP_ID)),
Err(e) => {
logging!(error, Type::File, "Failed to get the app home directory: {e}");
Err(anyhow::anyhow!("Failed to get the app homedirectory"))
}
}
::dirs::data_dir()
.map(|root| root.join(APP_ID))
.ok_or_else(|| anyhow::anyhow!("Failed to get the app home directory"))
}
pub fn preinit_app_data_dir() -> Result<PathBuf> {
if PORTABLE_FLAG.get().copied().unwrap_or(false) {
let executable = std::env::current_exe()?;
let parent = executable
.parent()
.ok_or_else(|| anyhow::anyhow!("portable executable has no parent directory"))?;
return Ok(parent.join(".config").join(APP_ID));
}
#[cfg(target_os = "macos")]
let root = PathBuf::from(std::env::var_os("HOME").ok_or_else(|| anyhow::anyhow!("HOME is unavailable"))?)
.join("Library/Application Support");
#[cfg(target_os = "linux")]
let root = std::env::var_os("XDG_DATA_HOME")
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(".local/share"));
#[cfg(windows)]
let root = PathBuf::from(std::env::var_os("APPDATA").ok_or_else(|| anyhow::anyhow!("APPDATA is unavailable"))?);
Ok(root.join(APP_ID))
app_home_dir()
}
pub fn app_resources_dir() -> Result<PathBuf> {