-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from kpcyrd/config
Allow passing additional arguments to spotify binary
- Loading branch information
Showing
8 changed files
with
284 additions
and
135 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[spotify] | ||
## Pass extra arguments to the spotify executable | ||
## You can test this with `spotify-launcher -v --skip-update --no-exec` | ||
#extra_arguments = [] | ||
## On HiDPI displays spotify doesn't pick up the scale factor automatically | ||
#extra_arguments = ["--force-device-scale-factor=2.0"] | ||
## On wayland you might need | ||
#extra_arguments = ["--enable-features=UseOzonePlatform", "--ozone-platform=wayland"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::errors::*; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct ConfigFile { | ||
#[serde(default)] | ||
pub spotify: SpotifyConfig, | ||
} | ||
|
||
impl ConfigFile { | ||
pub fn parse(s: &str) -> Result<ConfigFile> { | ||
let c = toml::from_str(s)?; | ||
Ok(c) | ||
} | ||
|
||
pub fn load_from(path: &Path) -> Result<ConfigFile> { | ||
info!("Loading configuration file at {:?}", path); | ||
let buf = fs::read_to_string(path) | ||
.with_context(|| anyhow!("Failed to read config file at {:?}", path))?; | ||
Self::parse(&buf) | ||
} | ||
|
||
pub fn locate_file() -> Result<Option<PathBuf>> { | ||
for path in &[dirs::config_dir(), Some(PathBuf::from("/etc/"))] { | ||
if let Some(path) = path { | ||
let path = path.join("spotify-launcher.conf"); | ||
debug!("Searching for configuration file at {:?}", path); | ||
if path.exists() { | ||
debug!("Found configuration file at {:?}", path); | ||
return Ok(Some(path)); | ||
} | ||
} | ||
} | ||
Ok(None) | ||
} | ||
|
||
pub fn load() -> Result<ConfigFile> { | ||
if let Some(path) = Self::locate_file()? { | ||
Self::load_from(&path) | ||
} else { | ||
info!("No configuration file found, using default config"); | ||
Ok(Self::default()) | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)] | ||
pub struct SpotifyConfig { | ||
#[serde(default)] | ||
pub extra_arguments: Vec<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_empty_config() -> Result<()> { | ||
let cf = ConfigFile::parse("")?; | ||
assert_eq!(cf, ConfigFile::default()); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_empty_spotify_config() -> Result<()> { | ||
let cf = ConfigFile::parse("[spotify]")?; | ||
assert_eq!(cf, ConfigFile::default()); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod apt; | ||
pub mod args; | ||
pub mod config; | ||
pub mod crypto; | ||
pub mod deb; | ||
pub mod errors; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters