Add repeat button

This commit is contained in:
Sijmen 2023-12-23 09:28:57 +01:00
parent d566d8792f
commit 9c7871ed87
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
3 changed files with 20 additions and 0 deletions

View File

@ -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/")?;

View File

@ -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,
};

View File

@ -62,6 +62,11 @@
hx-post="/shuffle"
class="control material-symbols-outlined {% if shuffle %}active{% endif %}" role="button" title="Shuffle"
>shuffle</button>
<button
hx-post="/repeat"
class="control material-symbols-outlined {% if repeat %}active{% endif %}" role="button" title="Repeat"
>repeat</button>
</div>
<div class="progress" style="width: {{ elapsed / duration * 100.0 }}%"></div>