Allow toggle to play from stopped state
This commit is contained in:
parent
69028816e8
commit
944c633792
2 changed files with 10 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "noise"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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",
|
||||
}
|
||||
}
|
||||
));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue