blob: 6e703867c94f5539e6e282d145d73c3444607bf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
diff --git a/src/daemon/buds_config.rs b/src/daemon/buds_config.rs
index 3929269..42aac1d 100644
--- a/src/daemon/buds_config.rs
+++ b/src/daemon/buds_config.rs
@@ -164,7 +164,11 @@ impl Config {
// Create missing folders and return the config file
pub async fn get_config_file() -> Result<PathBuf, String> {
- let conf_dir: PathBuf = get_home_dir().unwrap().join(".config").join("livebuds");
+ let conf_home: PathBuf = match get_xdg_config() {
+ Some(x) => x,
+ None => get_home_dir().unwrap().join(".config")
+ };
+ let conf_dir: PathBuf = conf_home.join("livebuds");
if !conf_dir.exists().await {
fs::create_dir_all(&conf_dir)
@@ -176,6 +180,13 @@ impl Config {
}
}
+pub fn get_xdg_config() -> Option<PathBuf> {
+ std::env::var_os("XDG_CONFIG_HOME")
+ .and_then(|xdg| if xdg.is_empty() { None } else { Some(xdg) })
+ .or(None)
+ .map(PathBuf::from)
+}
+
pub fn get_home_dir() -> Option<PathBuf> {
std::env::var_os("HOME")
.and_then(|home| if home.is_empty() { None } else { Some(home) })
|