From c9c06f8a3de282dc90856b45633085589a296e47 Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 21 Feb 2022 22:33:37 +0800 Subject: [PATCH] fix: wrong exe path --- src-tauri/Cargo.lock | 7 +++++++ src-tauri/Cargo.toml | 1 + src-tauri/src/core/verge.rs | 25 ++++++------------------- src-tauri/src/utils/resolve.rs | 2 +- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cdd3b8f..0040b7f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -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" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5c26261..97c828a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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" diff --git a/src-tauri/src/core/verge.rs b/src-tauri/src/core/verge.rs index be512e5..c6959fb 100644 --- a/src-tauri/src/core/verge.rs +++ b/src-tauri/src/core/verge.rs @@ -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 -} diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index d6b959d..bb1cc6a 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -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); }