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]
name = "noise"
version = "0.1.0"
version = "0.1.1"
edition = "2024"
[dependencies]

View file

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