Allow toggle to play from stopped state

This commit is contained in:
Nox Sluijtman 2025-06-19 09:48:46 +02:00
parent 69028816e8
commit 944c633792
Signed by: Egg
SSH key fingerprint: SHA256:2sG9X3C7Xvq2svGumz1/k7cm8l4G9+qAtAeugqB4J9M
2 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "noise" name = "noise"
version = "0.1.0" version = "0.1.1"
edition = "2024" edition = "2024"
[dependencies] [dependencies]

View file

@ -3,7 +3,7 @@ extern crate mpd;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use libnotify::Notification; use libnotify::Notification;
use mpd::{Client, Query, Song, Term}; use mpd::{Client, Query, Song, State, Term};
use std::time::Duration; use std::time::Duration;
#[derive(Parser)] #[derive(Parser)]
@ -104,7 +104,11 @@ fn main() {
Commands::Stop {} => conn.stop().unwrap(), Commands::Stop {} => conn.stop().unwrap(),
Commands::Toggle {} => { Commands::Toggle {} => {
if conn.status().unwrap().state == State::Stop {
conn.play().unwrap();
} else {
conn.toggle_pause().unwrap(); conn.toggle_pause().unwrap();
}
let status = get_status(conn, cli.verbose, n); let status = get_status(conn, cli.verbose, n);
println!("{status}"); println!("{status}");
} }
@ -266,9 +270,9 @@ fn get_status(mut client: Client, verbose: bool, notify: Notification) -> String
"[{status}] {duration}", "[{status}] {duration}",
status = { status = {
match client.status().unwrap().state { match client.status().unwrap().state {
mpd::State::Stop => "stopped", State::Stop => "stopped",
mpd::State::Pause => "paused", State::Pause => "paused",
mpd::State::Play => "playing", State::Play => "playing",
} }
} }
)); ));