diff --git a/src/main.rs b/src/main.rs index cebbe06..e011c69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ async fn post_consume(_req: tide::Request<()>) -> tide::Result { Ok("".into()) } -async fn post_shuffle(_req: tide::Request<()>) -> tide::Result { +async fn post_random(_req: tide::Request<()>) -> tide::Result { let mut mpd = mpd::get_instance().await; let status = mpd.command("status").await?.into_hashmap(); @@ -61,6 +61,24 @@ async fn post_repeat(_req: tide::Request<()>) -> tide::Result { Ok("".into()) } +async fn post_shuffle(_req: tide::Request<()>) -> tide::Result { + let mut mpd = mpd::get_instance().await; + mpd.command("shuffle").await?; + Ok("".into()) +} + +async fn post_single(_req: tide::Request<()>) -> tide::Result { + let mut mpd = mpd::get_instance().await; + + let status = mpd.command("status").await?.into_hashmap(); + let single = status["single"] == "1"; + + mpd.command(&format!("single {}", if single { 0 } else { 1 })) + .await?; + + Ok("".into()) +} + async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result<()> { // Update everything on connect sender.send("playlist", "", None).await?; @@ -106,8 +124,10 @@ async fn main() -> tide::Result<()> { app.at("/next").post(post_next); app.at("/consume").post(post_consume); - app.at("/shuffle").post(post_shuffle); + app.at("/random").post(post_random); app.at("/repeat").post(post_repeat); + app.at("/single").post(post_single); + app.at("/shuffle").post(post_shuffle); app.at("/static").serve_dir("static/")?; diff --git a/src/routes/player.rs b/src/routes/player.rs index 1d192f0..216e5b7 100644 --- a/src/routes/player.rs +++ b/src/routes/player.rs @@ -9,8 +9,9 @@ struct PlayerTemplate<'a> { name: Option, state: &'a str, consume: bool, - shuffle: bool, + random: bool, repeat: bool, + single: bool, elapsed: f32, duration: f32, } @@ -34,8 +35,9 @@ pub async fn get_player(_req: tide::Request<()>) -> tide::Result { name: None, state: &status["state"], consume: status["consume"] == "1", - shuffle: status["random"] == "1", + random: status["random"] == "1", repeat: status["repeat"] == "1", + single: status["single"] == "1", elapsed, duration, }; diff --git a/static/style.css b/static/style.css index 59449be..52e2af2 100644 --- a/static/style.css +++ b/static/style.css @@ -81,6 +81,10 @@ ul { align-items: center; } +.queue-header button { + margin-left: 0.75rem; +} + .queue-next { font-weight: bold; flex: 1; diff --git a/templates/index.html b/templates/index.html index 871905b..84841bf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -37,10 +37,14 @@
Next in queue
- +