Skip to content

Commit

Permalink
Merge branch 'erayaydin-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JojiiOfficial committed Jun 28, 2024
2 parents 0d57111 + da6116d commit df46706
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/daemon/buds_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ 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 = get_xdg_config()
.or_else(|| get_home_dir().map(|i| i.join(".config")))
.expect("Can't determine home directory!");
let conf_dir = conf_home.join("livebuds");

if !conf_dir.exists().await {
fs::create_dir_all(&conf_dir)
Expand All @@ -176,11 +179,20 @@ impl Config {
}
}

pub fn get_xdg_config() -> Option<PathBuf> {
try_env_var("XDG_CONFIG_HOME")
}

pub fn get_home_dir() -> Option<PathBuf> {
std::env::var_os("HOME")
.and_then(|home| if home.is_empty() { None } else { Some(home) })
.or(None)
.map(PathBuf::from)
try_env_var("HOME")
}

fn try_env_var(name: &str) -> Option<PathBuf>{
let xdg = std::env::var_os(name)?;
if xdg.is_empty(){
return None;
}
Some(PathBuf::from(xdg))
}

impl BudsConfig {
Expand Down

0 comments on commit df46706

Please sign in to comment.