Add button to shuffle the queue
This commit is contained in:
parent
31549b5b49
commit
16e4052890
4 changed files with 35 additions and 5 deletions
24
src/main.rs
24
src/main.rs
|
@ -37,7 +37,7 @@ async fn post_consume(_req: tide::Request<()>) -> tide::Result {
|
||||||
Ok("".into())
|
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 mut mpd = mpd::get_instance().await;
|
||||||
|
|
||||||
let status = mpd.command("status").await?.into_hashmap();
|
let status = mpd.command("status").await?.into_hashmap();
|
||||||
|
@ -61,6 +61,24 @@ async fn post_repeat(_req: tide::Request<()>) -> tide::Result {
|
||||||
Ok("".into())
|
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<()> {
|
async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result<()> {
|
||||||
// Update everything on connect
|
// Update everything on connect
|
||||||
sender.send("playlist", "", None).await?;
|
sender.send("playlist", "", None).await?;
|
||||||
|
@ -106,8 +124,10 @@ async fn main() -> tide::Result<()> {
|
||||||
app.at("/next").post(post_next);
|
app.at("/next").post(post_next);
|
||||||
|
|
||||||
app.at("/consume").post(post_consume);
|
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("/repeat").post(post_repeat);
|
||||||
|
app.at("/single").post(post_single);
|
||||||
|
app.at("/shuffle").post(post_shuffle);
|
||||||
|
|
||||||
app.at("/static").serve_dir("static/")?;
|
app.at("/static").serve_dir("static/")?;
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@ struct PlayerTemplate<'a> {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
state: &'a str,
|
state: &'a str,
|
||||||
consume: bool,
|
consume: bool,
|
||||||
shuffle: bool,
|
random: bool,
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
|
single: bool,
|
||||||
elapsed: f32,
|
elapsed: f32,
|
||||||
duration: f32,
|
duration: f32,
|
||||||
}
|
}
|
||||||
|
@ -34,8 +35,9 @@ pub async fn get_player(_req: tide::Request<()>) -> tide::Result {
|
||||||
name: None,
|
name: None,
|
||||||
state: &status["state"],
|
state: &status["state"],
|
||||||
consume: status["consume"] == "1",
|
consume: status["consume"] == "1",
|
||||||
shuffle: status["random"] == "1",
|
random: status["random"] == "1",
|
||||||
repeat: status["repeat"] == "1",
|
repeat: status["repeat"] == "1",
|
||||||
|
single: status["single"] == "1",
|
||||||
elapsed,
|
elapsed,
|
||||||
duration,
|
duration,
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,10 @@ ul {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.queue-header button {
|
||||||
|
margin-left: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
.queue-next {
|
.queue-next {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
|
@ -37,10 +37,14 @@
|
||||||
|
|
||||||
<div class="queue-header">
|
<div class="queue-header">
|
||||||
<div class="queue-next">Next in queue</div>
|
<div class="queue-next">Next in queue</div>
|
||||||
<button class="queue-clear" hx-delete="/queue" hx-swap="none">
|
<button hx-delete="/queue" hx-swap="none">
|
||||||
<span class="material-symbols-outlined">playlist_remove</span>
|
<span class="material-symbols-outlined">playlist_remove</span>
|
||||||
Clear
|
Clear
|
||||||
</button>
|
</button>
|
||||||
|
<button hx-post="/shuffle" hx-swap="none">
|
||||||
|
<span class="material-symbols-outlined">shuffle</span>
|
||||||
|
Shuffle
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="queue" hx-trigger="sse:playlist,sse:player" hx-get="/queue"></div>
|
<div class="queue" hx-trigger="sse:playlist,sse:player" hx-get="/queue"></div>
|
||||||
|
|
Loading…
Reference in a new issue