Add repeat button
This commit is contained in:
parent
d566d8792f
commit
9c7871ed87
3 changed files with 20 additions and 0 deletions
13
src/main.rs
13
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/")?;
|
||||
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue