From af1db9b2bae0747373763cf50862dd7e10fd5bcf Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Sat, 1 Feb 2025 09:57:30 -0600 Subject: [PATCH] network folders even for mainnet --- harbor-client/src/lib.rs | 29 +++++++++++++++++------------ harbor-ui/src/bridge.rs | 4 ++-- harbor-ui/src/config.rs | 4 ++-- harbor-ui/src/main.rs | 12 ++++++++++++ harbor-ui/src/routes/settings.rs | 2 +- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/harbor-client/src/lib.rs b/harbor-client/src/lib.rs index 681d571..9823ea4 100644 --- a/harbor-client/src/lib.rs +++ b/harbor-client/src/lib.rs @@ -31,18 +31,22 @@ use tokio::sync::RwLock; use uuid::Uuid; /// The directory where all application data is stored -/// Defaults to ~/.harbor, if we're on a test network -/// Otherwise defaults to ~/.harbor/ -pub fn data_dir(network: Network) -> PathBuf { +/// Defaults to ~/.harbor as the root directory +/// Network-specific data goes in ~/.harbor/ +pub fn data_dir(network: Option) -> PathBuf { let home = home::home_dir().expect("Could not find home directory"); - let default = home.join(".harbor"); - match network { - Network::Bitcoin => default, - Network::Testnet => default.join("testnet3"), - Network::Testnet4 => default.join("testnet4"), - Network::Regtest => default.join("regtest"), - Network::Signet => default.join("signet"), - _ => panic!("Invalid network"), + let root = home.join(".harbor"); + if let Some(network) = network { + match network { + Network::Bitcoin => root.join("bitcoin"), + Network::Testnet => root.join("testnet3"), + Network::Testnet4 => root.join("testnet4"), + Network::Regtest => root.join("regtest"), + Network::Signet => root.join("signet"), + _ => panic!("Invalid network"), + } + } else { + root } } @@ -305,11 +309,12 @@ impl HarborCore { let lightning_module = client .get_first_module::() .expect("must have ln module"); + log::info!("Lightning module: {:?}", lightning_module.id); let gateway = select_gateway(&client) .await .ok_or(anyhow!("Internal error: No gateway found for federation"))?; - + log::info!("Gateway: {gateway:?}"); let desc = Description::new(String::new()).expect("empty string is valid"); let (op_id, invoice, preimage) = lightning_module .create_bolt11_invoice( diff --git a/harbor-ui/src/bridge.rs b/harbor-ui/src/bridge.rs index 96f092d..0b33526 100644 --- a/harbor-ui/src/bridge.rs +++ b/harbor-ui/src/bridge.rs @@ -166,8 +166,8 @@ pub fn run_core() -> impl Stream { .await .expect("should send"); - // Create the datadir if it doesn't exist - let path = PathBuf::from(&data_dir(network)); + // Create the network-specific datadir if it doesn't exist + let path = PathBuf::from(&data_dir(Some(network))); std::fs::create_dir_all(&path).expect("Could not create datadir"); log::info!("Using datadir: {path:?}"); diff --git a/harbor-ui/src/config.rs b/harbor-ui/src/config.rs index 95fa9af..53dc11f 100644 --- a/harbor-ui/src/config.rs +++ b/harbor-ui/src/config.rs @@ -19,7 +19,7 @@ impl Default for Config { pub fn read_config() -> anyhow::Result { // Create the datadir if it doesn't exist - let root = PathBuf::from(&data_dir(Network::Bitcoin)); + let root = PathBuf::from(&data_dir(None)); std::fs::create_dir_all(&root).expect("Could not create datadir"); let config_path = root.join("harbor.config.json"); @@ -42,7 +42,7 @@ pub fn read_config() -> anyhow::Result { } pub fn write_config(config: &Config) -> anyhow::Result<()> { - let root = PathBuf::from(&data_dir(Network::Bitcoin)); + let root = PathBuf::from(&data_dir(None)); let config_path = root.join("harbor.config.json"); std::fs::create_dir_all(&root).expect("Could not create datadir"); diff --git a/harbor-ui/src/main.rs b/harbor-ui/src/main.rs index a85a9d3..4c084b5 100644 --- a/harbor-ui/src/main.rs +++ b/harbor-ui/src/main.rs @@ -342,6 +342,18 @@ impl HarborWallet { write_config(&new_config).expect("Failed to write config"); + // Relaunch the app + use std::env; + use std::process::Command; + + let args: Vec = env::args().collect(); + let executable = &args[0]; + + Command::new(executable) + .args(&args[1..]) + .spawn() + .expect("Failed to relaunch"); + std::process::exit(0); } Message::Batch(messages) => { diff --git a/harbor-ui/src/routes/settings.rs b/harbor-ui/src/routes/settings.rs index 87f19cb..3e4a5ac 100644 --- a/harbor-ui/src/routes/settings.rs +++ b/harbor-ui/src/routes/settings.rs @@ -26,7 +26,7 @@ pub fn settings(harbor: &HarborWallet) -> Element { Message::SetConfirmModal(Some(crate::components::ConfirmModalState { title: "Are you sure?".to_string(), description: format!( - "Changing network requires a restart, are you sure you want to change to {net}" + "Changing network requires a restart, are you sure you want to change to {net}?" ), confirm_action: Box::new(Message::ChangeNetwork(net)), cancel_action: Box::new(Message::SetConfirmModal(None)),