diff --git a/Cargo.lock b/Cargo.lock index 8dc24a1..f2cb356 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,6 +541,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" +dependencies = [ + "dirs-sys 0.4.1", +] + [[package]] name = "dirs" version = "1.0.5" @@ -558,7 +567,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", ] [[package]] @@ -572,6 +581,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users 0.4.6", + "windows-sys 0.48.0", +] + [[package]] name = "either" version = "1.13.0" @@ -1194,6 +1215,7 @@ dependencies = [ "chrono-english", "colog", "colored", + "directories", "env_logger", "interim", "itertools", @@ -1204,7 +1226,6 @@ dependencies = [ "regex", "rustyline", "tokio", - "xdg", ] [[package]] @@ -1405,6 +1426,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parse_datetime" version = "0.5.0" @@ -2661,12 +2688,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "xdg" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" - [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 7a67402..4493b3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ default-run = "mostr" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -xdg = "2.5" +directories = "5.0" itertools = "0.12" log = "0.4" chrono = "0.4" diff --git a/src/main.rs b/src/main.rs index 16e3f98..eddd529 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::time::Duration; use chrono::Local; use colored::Colorize; +use directories::ProjectDirs; use env_logger::{Builder, Target, WriteStyle}; use itertools::Itertools; use log::{debug, error, info, trace, warn, LevelFilter}; @@ -167,14 +168,15 @@ async fn main() -> Result<()> { ); builder.init(); - let config_dir = or_warn!(xdg::BaseDirectories::new(), "Could not determine config directory") - .and_then(|d| or_warn!(d.create_config_directory("mostr"), "Could not create config directory")) - .unwrap_or(PathBuf::new()); + let config_dir = + ProjectDirs::from("", "", "mostr") + .map(|p| p.config_dir().to_path_buf()) + .unwrap_or(PathBuf::new()); let keysfile = config_dir.join("key"); let relayfile = config_dir.join("relays"); - let keys = if let Ok(Ok(key)) = fs::read_to_string(&keysfile).map(|s| Keys::from_str(&s)) { - key + let keys = if let Ok(Ok(keys)) = fs::read_to_string(&keysfile).map(|s| Keys::from_str(&s)) { + keys } else { warn!("Could not read keys from {}", keysfile.to_string_lossy()); let line = rl.readline("Secret key? (leave blank to generate and save a new keypair) ")?;