fix: wrong exe path

This commit is contained in:
GyDi 2022-02-21 22:33:37 +08:00
parent 72127979c3
commit c9c06f8a3d
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084
4 changed files with 15 additions and 20 deletions

7
src-tauri/Cargo.lock generated
View File

@ -448,6 +448,7 @@ dependencies = [
"auto-launch",
"chrono",
"dirs",
"dunce",
"log",
"log4rs",
"port_scanner",
@ -868,6 +869,12 @@ dependencies = [
"dtoa",
]
[[package]]
name = "dunce"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
[[package]]
name = "easy-parallel"
version = "3.2.0"

View File

@ -14,6 +14,7 @@ tauri-build = { version = "1.0.0-rc.3", features = [] }
[dependencies]
dirs = "4.0.0"
dunce = "1.0.2"
chrono = "0.4.19"
serde_json = "1.0"
serde_yaml = "0.8"

View File

@ -5,7 +5,7 @@ use crate::{
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tauri::{api::path::resource_dir, async_runtime::Mutex};
use tauri::{async_runtime::Mutex, utils::platform::current_exe};
/// ### `verge.yaml` schema
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
@ -122,13 +122,11 @@ impl Verge {
}
/// init the auto launch
pub fn init_launch(&mut self, package_info: &tauri::PackageInfo) {
let app_name = "clash-verge";
let app_path = get_app_path(app_name);
let app_path = resource_dir(package_info, &tauri::Env::default())
.unwrap()
.join(app_path);
let app_path = app_path.as_os_str().to_str().unwrap();
pub fn init_launch(&mut self) {
let app_exe = current_exe().unwrap();
let app_exe = dunce::canonicalize(app_exe).unwrap();
let app_name = app_exe.file_stem().unwrap().to_str().unwrap();
let app_path = app_exe.as_os_str().to_str().unwrap();
let auto = AutoLaunchBuilder::new()
.set_app_name(app_name)
@ -324,14 +322,3 @@ impl Verge {
});
}
}
// Get the target app_path
fn get_app_path(app_name: &str) -> String {
#[cfg(target_os = "linux")]
let ext = "";
#[cfg(target_os = "macos")]
let ext = "";
#[cfg(target_os = "windows")]
let ext = ".exe";
String::from(app_name) + ext
}

View File

@ -31,7 +31,7 @@ pub fn resolve_setup(app: &App) {
}
verge.init_sysproxy(clash.info.port.clone());
verge.init_launch(app.package_info());
verge.init_launch();
if let Err(err) = verge.sync_launch() {
log::error!("{}", err);
}