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]
|
[package]
|
||||||
name = "noise"
|
name = "noise"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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 {} => {
|
||||||
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);
|
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",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue