feat: add --pause flag

This commit is contained in:
talwat 2024-10-07 14:39:08 +02:00
parent 6b157dd457
commit c7d46e9872
3 changed files with 10 additions and 2 deletions

View File

@ -17,6 +17,10 @@ struct Args {
#[clap(long, short)]
minimalist: bool,
/// Whether to start lowfi paused
#[clap(long, short)]
paused: bool,
/// The command that was ran.
/// This is [None] if no command was specified.
#[command(subcommand)]

View File

@ -74,7 +74,7 @@ pub async fn play(args: Args) -> eyre::Result<()> {
let properties = InitialProperties::load().await?;
let (tx, rx) = mpsc::channel(8);
let player = Arc::new(Player::new(!args.alternate).await?);
let player = Arc::new(Player::new(!args.alternate, &args).await?);
let ui = task::spawn(ui::start(Arc::clone(&player), tx.clone(), args));
tx.send(Messages::Init).await?;

View File

@ -21,6 +21,7 @@ use tokio::{
use crate::{
play::InitialProperties,
tracks::{DecodedTrack, Track, TrackInfo},
Args,
};
pub mod downloader;
@ -141,7 +142,7 @@ impl Player {
/// `silent` can control whether alsa's output should be redirected,
/// but this option is only applicable on Linux, as on MacOS & Windows
/// it will never be silent.
pub async fn new(silent: bool) -> eyre::Result<Self> {
pub async fn new(silent: bool, args: &Args) -> eyre::Result<Self> {
let (_stream, handle) = if silent && cfg!(target_os = "linux") {
Self::silent_get_output_stream()?
} else {
@ -149,6 +150,9 @@ impl Player {
};
let sink = Sink::try_new(&handle)?;
if args.paused {
sink.pause();
}
let player = Self {
tracks: RwLock::new(VecDeque::with_capacity(5)),