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
Changes from 1 commit
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
14 changes: 6 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ pub enum Backend {
Rodio,
}

const DEFAULT_BACKEND: Backend = if cfg!(target_os = "macos") {
Backend::PortAudio
} else {
Backend::Alsa
};
fn default_backend() -> Backend {
return Backend::from_str(BACKEND_VALUES.first().unwrap()).unwrap_or(Backend::Alsa);
fxsalazar marked this conversation as resolved.
Show resolved Hide resolved
}

impl FromStr for Backend {
type Err = ParseError;
Expand Down Expand Up @@ -655,7 +653,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
let backend = config
.shared_config
.backend
.unwrap_or(DEFAULT_BACKEND)
.unwrap_or(default_backend())
.to_string();

let volume_controller = config
Expand Down Expand Up @@ -819,11 +817,11 @@ mod tests {
assert_eq!(merged_config, spotifyd_section);
}
#[test]
fn default_backend_by_os() {
fn test_default_backend() {
let spotifyd_config = get_internal_config(CliConfig::default());
assert_eq!(
spotifyd_config.backend.unwrap(),
DEFAULT_BACKEND.to_string()
default_backend().to_string()
);
}
}