Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read config file from $XDG_CONFIG_HOME/spotify-adblock/config.toml #175

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ $ flatpak override --user --reset com.spotify.Client
```

## Configuration
The allowlist and denylist can be configured in a config file located at (in ascending order of precedence):
* `/etc/spotify-adblock/config.toml` *(default)*
* `~/.config/spotify-adblock/config.toml` *(default for Flatpak)*
The allowlist and denylist can be configured in a config file located at (in descending order of precedence):
* `config.toml` in the working directory
* `$XDG_CONFIG_HOME/spotify-adblock/config.toml`
* `~/.config/spotify-adblock/config.toml`
* `/etc/spotify-adblock/config.toml` *(default)*
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