From: Simon Tatham Date: Sat, 23 Dec 2023 11:58:04 +0000 (+0000) Subject: Try using xdg to get the config directory location. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=ac43b1ac470234f925f866cd3b2e97f49366d04b;p=mastodonochrome.git Try using xdg to get the config directory location. --- diff --git a/Cargo.toml b/Cargo.toml index 10b6e22..5f6a2c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ reqwest = { version = "0.11.23", features = ["blocking"] } serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" unicode-width = "0.1.5" +xdg = "2.5.2" diff --git a/src/main.rs b/src/main.rs index f562a74..fd695d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,10 @@ use std::io::Read; fn main() { - let auth = std::fs::read_to_string( - "/home/simon/.config/mastodonochrome/auth").unwrap(); + let xdg_dirs = xdg::BaseDirectories::with_prefix("mastodonochrome") + .unwrap(); + let authfile = xdg_dirs.get_config_file("auth"); + let auth = std::fs::read_to_string(authfile).unwrap(); let auth: serde_json::Value = serde_json::from_str(&auth).unwrap(); let auth = &auth["user_token"].as_str().unwrap();