Skip to content

Commit

Permalink
Make Daemon feature imply streaming feature (#376)
Browse files Browse the repository at this point in the history
* Streaming/audio-backend feature compile time check

Forbids compilation of one non functional feature combination

Now, `cargo check --no-default-features --features streaming` (lacking
an audio backend) returns a compilation error instead of silently
producing a failing binary.

* Make Daemon feature imply streaming feature

Remove runtime error, favouring compile time verification
  • Loading branch information
LucasFA authored Feb 25, 2024
1 parent 157b361 commit 67e9851
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spotify_player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ image = ["viuer", "dep:image"]
sixel = ["image", "viuer/sixel"]
notify = ["notify-rust"]
clipboard = ["copypasta"]
daemon = ["daemonize"]
daemon = ["daemonize", "streaming"]

default = ["rodio-backend", "media-control", "clipboard"]

Expand Down
4 changes: 0 additions & 4 deletions spotify_player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ fn main() -> Result<()> {
eprintln!("Running the application as a daemon on windows/macos with `media-control` feature enabled is not supported!");
std::process::exit(1);
}
if cfg!(not(feature = "streaming")) {
eprintln!("`streaming` feature must be enabled to run the application as a daemon!");
std::process::exit(1);
}

tracing::info!("Starting the application as a daemon...");
let daemonize = daemonize::Daemonize::new();
Expand Down
22 changes: 22 additions & 0 deletions spotify_player/src/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ use librespot_playback::{
use rspotify::model::TrackId;
use serde::Serialize;

#[cfg(not(any(
feature = "rodio-backend",
feature = "alsa-backend",
feature = "pulseaudio-backend",
feature = "portaudio-backend",
feature = "jackaudio-backend",
feature = "rodiojack-backend",
feature = "sdl-backend",
feature = "gstreamer-backend"
)))]
compile_error!("Streaming feature is enabled but no audio backend has been selected. Consider adding one of the following features:
rodio-backend,
alsa-backend,
pulseaudio-backend,
portaudio-backend,
jackaudio-backend,
rodiojack-backend,
sdl-backend,
gstreamer-backend
For more information, visit https://github.com/aome510/spotify-player?tab=readme-ov-file#streaming
");

#[derive(Debug, Serialize)]
enum PlayerEvent {
Changed {
Expand Down

0 comments on commit 67e9851

Please sign in to comment.