From 944c633792bb4340bc1297ecab6d7a1a5a115cb8 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Thu, 19 Jun 2025 09:48:46 +0200 Subject: [PATCH] Allow toggle to play from stopped state --- Cargo.toml | 2 +- src/main.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 629f52e..fc54abd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "noise" -version = "0.1.0" +version = "0.1.1" edition = "2024" [dependencies] diff --git a/src/main.rs b/src/main.rs index b2a3caa..7744290 100644 --- a/src/main.rs +++ b/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", } } ));