Check if audio is busy in separate function
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -64,15 +64,10 @@ async fn main() {
|
||||
}),
|
||||
|
||||
rx.filter_map(|()| async {
|
||||
AUDIO_CHILD.with(|cell| {
|
||||
if let Some(ref mut audio_child) = *cell.borrow_mut() {
|
||||
if let Ok(None) = audio_child.try_wait() {
|
||||
debug!("doorbell still ringing, ignoring press");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
})?;
|
||||
if audio_busy() {
|
||||
debug!("doorbell still ringing, ignoring press");
|
||||
return None;
|
||||
}
|
||||
debug!("Playing doorbell chime");
|
||||
match process::Command::new("mplayer")
|
||||
.arg("static/outdoor.mp3")
|
||||
@@ -92,3 +87,14 @@ async fn main() {
|
||||
let routes = root.or(events);
|
||||
warp::serve(routes).run(([0, 0, 0, 0], 8060)).await;
|
||||
}
|
||||
|
||||
fn audio_busy() -> bool {
|
||||
AUDIO_CHILD.with(|cell| {
|
||||
if let Some(ref mut audio_child) = *cell.borrow_mut() {
|
||||
if let Ok(None) = audio_child.try_wait() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user