Skip to content

Set conditional default backend #1158

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

Merged
merged 4 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 13 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub enum Backend {
Rodio,
}

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

impl FromStr for Backend {
type Err = ParseError;

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

let volume_controller = config
Expand Down Expand Up @@ -812,4 +816,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