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

Set conditional default backend #1158

Merged
merged 4 commits into from
Feb 2, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ tags

*.rustfmt

.idea
.idea
.vscode
21 changes: 20 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ use url::Url;

const CONFIG_FILE_NAME: &str = "spotifyd.conf";

#[cfg(not(any(
feature = "pulseaudio_backend",
feature = "portaudio_backend",
feature = "alsa_backend",
feature = "rodio_backend"
)))]
compile_error!("At least one of the backend features is required!");
static BACKEND_VALUES: &[&str] = &[
#[cfg(feature = "alsa_backend")]
"alsa",
Expand All @@ -39,6 +46,10 @@ pub enum Backend {
Rodio,
}

fn default_backend() -> Backend {
return Backend::from_str(BACKEND_VALUES.first().unwrap()).unwrap();
}

impl FromStr for Backend {
type Err = ParseError;

Expand Down Expand Up @@ -649,7 +660,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
let backend = config
.shared_config
.backend
.unwrap_or(Backend::Alsa)
.unwrap_or_else(default_backend)
.to_string();

let volume_controller = config
Expand Down Expand Up @@ -812,4 +823,12 @@ mod tests {
spotifyd_section.username = Some("testUserName".to_string());
assert_eq!(merged_config, spotifyd_section);
}
#[test]
fn test_default_backend() {
let spotifyd_config = get_internal_config(CliConfig::default());
assert_eq!(
spotifyd_config.backend.unwrap(),
default_backend().to_string()
);
}
}
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn get_shell_ffi() -> Option<String> {

let username = whoami::username();
let output = Command::new("dscl")
.args(&[".", "-read", &format!("/Users/{}", username), "UserShell"])
.args([".", "-read", &format!("/Users/{}", username), "UserShell"])
.output()
.ok()?;

Expand Down