Skip to content

Commit

Permalink
Read config file from $XDG_CONFIG_HOME/spotify-adblock/config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
guihkx committed Sep 14, 2024
1 parent f6aa1a9 commit 1f14248
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use lazy_static::lazy_static;
use libc::{addrinfo, c_char, dlsym, EAI_FAIL, RTLD_NEXT};
use regex::RegexSet;
use serde::Deserialize;
use std::{ffi::CStr, fs::read_to_string, mem, path::PathBuf, ptr::null, slice::from_raw_parts, string::String};
use std::{env, ffi::CStr, fs::read_to_string, mem, path::PathBuf, ptr::null, slice::from_raw_parts, string::String};

macro_rules! hook {
($function_name:ident($($parameter_name:ident: $parameter_type:ty),*) -> $return_type:ty => $new_function_name:ident $body:block) => {
Expand Down Expand Up @@ -41,8 +41,11 @@ lazy_static! {
static ref CONFIG: Config = {
let config_paths = vec![
PathBuf::from("config.toml"),
#[allow(deprecated)] // std::env::home_dir() is only broken on Windows
std::env::home_dir().unwrap().join(".config/spotify-adblock/config.toml"),
match env::var("XDG_CONFIG_HOME") {
Ok(xdg_config_home) => PathBuf::from(xdg_config_home),
#[allow(deprecated)] // std::env::home_dir() is only broken on Windows
Err(_) => PathBuf::from(env::home_dir().unwrap()).join(".config")
}.join("spotify-adblock/config.toml"),
PathBuf::from("/etc/spotify-adblock/config.toml"),
];

Expand Down

0 comments on commit 1f14248

Please sign in to comment.