diff --git a/src/app_dir.rs b/src/app_dir.rs index b01b09356..131a4e52b 100644 --- a/src/app_dir.rs +++ b/src/app_dir.rs @@ -1,7 +1,7 @@ -use directories::{ProjectDirs, UserDirs}; +use dash_sdk::dpp::dashcore::Network; +use directories::ProjectDirs; use std::fs; use std::path::PathBuf; -use dash_sdk::dpp::dashcore::Network; const QUALIFIER: &str = ""; // Typically empty on macOS and Linux const ORGANIZATION: &str = ""; @@ -26,6 +26,8 @@ pub fn app_user_data_dir_path() -> Result { pub fn core_user_data_dir_path() -> Result { #[cfg(target_os = "linux")] { + use directories::UserDirs; + UserDirs::new() .and_then(|dirs| dirs.home_dir().to_owned().into()) .map(|home_dir| home_dir.join(".dashcore")) @@ -43,7 +45,10 @@ pub fn core_user_data_dir_path() -> Result { } } -pub fn core_cookie_path(network: Network, devnet_name: &Option) -> Result { +pub fn core_cookie_path( + network: Network, + devnet_name: &Option, +) -> Result { core_user_data_dir_path().map(|path| { let network_dir = match network { Network::Dash => "", @@ -87,13 +92,38 @@ pub fn copy_env_file_if_not_exists() { app_user_data_dir_path().expect("Failed to determine application data directory"); let env_file_in_app_dir = app_data_dir.join(".env".to_string()); if !env_file_in_app_dir.exists() || !env_file_in_app_dir.is_file() { + // Get the directory where the executable is located + let exe_dir = std::env::current_exe() + .ok() + .and_then(|path| path.parent().map(|p| p.to_path_buf())); + + if let Some(exe_dir) = exe_dir { + let env_example_file_in_exe_dir = exe_dir.join(".env.example"); + if env_example_file_in_exe_dir.exists() && env_example_file_in_exe_dir.is_file() { + fs::copy(&env_example_file_in_exe_dir, env_file_in_app_dir) + .expect("Failed to copy env file"); + return; + } + + let env_file_in_exe_dir = exe_dir.join(".env"); + if env_file_in_exe_dir.exists() && env_file_in_exe_dir.is_file() { + fs::copy(&env_file_in_exe_dir, env_file_in_app_dir) + .expect("Failed to copy env file"); + return; + } + } + + // Fallback to current working directory let env_example_file_in_exe_dir = PathBuf::from(".env.example"); if env_example_file_in_exe_dir.exists() && env_example_file_in_exe_dir.is_file() { fs::copy(&env_example_file_in_exe_dir, env_file_in_app_dir) .expect("Failed to copy env file"); } else { let env_file_in_exe_dir = PathBuf::from(".env"); - fs::copy(&env_file_in_exe_dir, env_file_in_app_dir).expect("Failed to copy env file"); + if env_file_in_exe_dir.exists() && env_file_in_exe_dir.is_file() { + fs::copy(&env_file_in_exe_dir, env_file_in_app_dir) + .expect("Failed to copy env file"); + } } } } diff --git a/src/backend_task/core/mod.rs b/src/backend_task/core/mod.rs index 34fdbea13..7a4be1418 100644 --- a/src/backend_task/core/mod.rs +++ b/src/backend_task/core/mod.rs @@ -57,8 +57,10 @@ impl AppContext { let config = Config::load().map_err(|e| format!("Failed to load config: {}", e))?; // Get chain locks - let mainnet_result = - Self::get_best_chain_lock(config.config_for_network(Network::Dash), Network::Dash); + let mainnet_result = Self::get_best_chain_lock( + config.config_for_network(Network::Dash), + Network::Dash, + ); let testnet_result = Self::get_best_chain_lock( config.config_for_network(Network::Testnet), Network::Testnet, diff --git a/src/backend_task/core/start_dash_qt.rs b/src/backend_task/core/start_dash_qt.rs index 2cf92c880..233c05441 100644 --- a/src/backend_task/core/start_dash_qt.rs +++ b/src/backend_task/core/start_dash_qt.rs @@ -53,8 +53,18 @@ impl AppContext { if overwrite_dash_conf { // Construct the full path to the config file - let current_dir = env::current_dir()?; - let config_path = current_dir.join(config_file); + // Try to get the directory where the executable is located first + let config_path = if let Ok(exe_path) = env::current_exe() { + if let Some(exe_dir) = exe_path.parent() { + exe_dir.join(config_file) + } else { + // Fallback to current working directory + env::current_dir()?.join(config_file) + } + } else { + // Fallback to current working directory + env::current_dir()?.join(config_file) + }; command.arg(format!("-conf={}", config_path.display())); } else if network == Network::Testnet { command.arg("-testnet"); diff --git a/src/context.rs b/src/context.rs index 3d0066cbe..8a2a4c96a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -87,7 +87,8 @@ impl AppContext { "http://{}:{}", network_config.core_host, network_config.core_rpc_port ); - let cookie_path = core_cookie_path(network, &network_config.devnet_name).expect("expected to get cookie path"); + let cookie_path = core_cookie_path(network, &network_config.devnet_name) + .expect("expected to get cookie path"); // Try cookie authentication first let core_client = match Client::new(&addr, Auth::CookieFile(cookie_path.clone())) { @@ -106,7 +107,8 @@ impl AppContext { ), ) } - }.expect("Failed to create CoreClient"); + } + .expect("Failed to create CoreClient"); let wallets: BTreeMap<_, _> = db .get_wallets(&network) diff --git a/src/ui/identities/add_existing_identity_screen.rs b/src/ui/identities/add_existing_identity_screen.rs index 5f677baf7..02c5ad6d9 100644 --- a/src/ui/identities/add_existing_identity_screen.rs +++ b/src/ui/identities/add_existing_identity_screen.rs @@ -189,7 +189,7 @@ impl AddExistingIdentityScreen { .on_hover_text("Alias is optional. It is only used to help identify the identity in Dash Evo Tool. It isn't saved to Dash Platform."); if response.clicked() { self.show_pop_up_info = Some("Alias is optional. It is only used to help identify the identity in Dash Evo Tool. It isn't saved to Dash Platform.".to_string()); - } + } }); ui.text_edit_singleline(&mut self.alias_input); ui.label(""); @@ -224,14 +224,14 @@ impl AddExistingIdentityScreen { // First column: the label & info icon, combined horizontally ui.horizontal(|ui| { ui.label(format!("Private Key {} (Hex or WIF):", i + 1)); - + let info_icon = egui::Label::new("ℹ").sense(egui::Sense::click()); let response = ui .add(info_icon) .on_hover_text("You don't need to add all or even any private keys here. \ Private keys can be added later. However, without private keys, \ you won't be able to sign any transactions."); - + if response.clicked() { self.show_pop_up_info = Some( "You don't need to add all or even any private keys here. \ @@ -244,15 +244,15 @@ impl AddExistingIdentityScreen { // Second column: the text field ui.text_edit_singleline(key); - + // Third column: the remove button if ui.button("-").clicked() { keys_to_remove.push(i); } - + ui.end_row(); } - + // Remove the keys after the loop to avoid borrowing conflicts for i in keys_to_remove.iter().rev() { self.keys_input.remove(*i);