Skip to content

Commit

Permalink
killall_mplayer button
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanja-4732 committed Aug 22, 2023
1 parent f4bf5a7 commit b8900e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use leptos::{ev::close, *};
use leptos_router::*;

use crate::app::sound_button::SoundButton;
use crate::core::{get_sounds, get_sounds_strings, parse_sounds, Sound, HL_SOUNDS_STRING};
use crate::core::{
get_sounds, get_sounds_strings, kill_mplayer, parse_sounds, Sound, HL_SOUNDS_STRING,
};

async fn load_data() -> i32 {
42
Expand Down Expand Up @@ -53,6 +55,8 @@ pub fn App(cx: Scope) -> impl IntoView {
sounds
};

let kill_action = create_action(cx, |_: &()| async move { kill_mplayer().await.unwrap() });

// the resource's loading() method gives us a
// signal to indicate whether it's currently loading
let loading = async_data.loading();
Expand All @@ -72,10 +76,15 @@ pub fn App(cx: Scope) -> impl IntoView {
"Reload data"
</button>

// <button on:click=move |_| {
// set_show_hl_sounds.update(|n| *n = !*n);
// }>
// "Toggle hl-sounds"
// </button>
<button on:click=move |_| {
set_show_hl_sounds.update(|n| *n = !*n);
kill_action.dispatch(());
}>
"Toggle hl-sounds"
"Kill mplayer"
</button>
</div>

Expand Down
14 changes: 13 additions & 1 deletion src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ pub async fn play_sound(url: String) -> Result<(), gloo_net::Error> {
.cache(RequestCache::NoCache)
.build()?;

let resp = req.send().await?;
req.send().await?;

Ok(())
}

pub async fn kill_mplayer() -> Result<(), gloo_net::Error> {
let url = format!("http://licht.realraum.at:4242/api/v1/killall_mplayer");
let req = RequestBuilder::new(&url)
.method(Method::GET)
.cache(RequestCache::NoCache)
.build()?;

req.send().await?;

Ok(())
}
Expand Down

0 comments on commit b8900e0

Please sign in to comment.