From 9c7871ed874da2db61ea3eee6a088e5aeae58cf3 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Sat, 23 Dec 2023 09:28:57 +0100 Subject: [PATCH] Add repeat button --- src/main.rs | 13 +++++++++++++ src/routes/player.rs | 2 ++ templates/player.html | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8bec5d0..cebbe06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,18 @@ async fn post_shuffle(_req: tide::Request<()>) -> tide::Result { Ok("".into()) } +async fn post_repeat(_req: tide::Request<()>) -> tide::Result { + let mut mpd = mpd::get_instance().await; + + let status = mpd.command("status").await?.into_hashmap(); + let repeat = status["repeat"] == "1"; + + mpd.command(&format!("repeat {}", if repeat { 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?; @@ -95,6 +107,7 @@ async fn main() -> tide::Result<()> { app.at("/consume").post(post_consume); app.at("/shuffle").post(post_shuffle); + app.at("/repeat").post(post_repeat); app.at("/static").serve_dir("static/")?; diff --git a/src/routes/player.rs b/src/routes/player.rs index af055be..1d192f0 100644 --- a/src/routes/player.rs +++ b/src/routes/player.rs @@ -10,6 +10,7 @@ struct PlayerTemplate<'a> { state: &'a str, consume: bool, shuffle: bool, + repeat: bool, elapsed: f32, duration: f32, } @@ -34,6 +35,7 @@ pub async fn get_player(_req: tide::Request<()>) -> tide::Result { state: &status["state"], consume: status["consume"] == "1", shuffle: status["random"] == "1", + repeat: status["repeat"] == "1", elapsed, duration, }; diff --git a/templates/player.html b/templates/player.html index bbf5259..9835e6d 100644 --- a/templates/player.html +++ b/templates/player.html @@ -62,6 +62,11 @@ hx-post="/shuffle" class="control material-symbols-outlined {% if shuffle %}active{% endif %}" role="button" title="Shuffle" >shuffle + +