From 288ad14060603b51e9367b25861399072f71c4f2 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Mon, 13 Sep 2021 11:59:56 -0600 Subject: [PATCH] adds bep to embassy startup sequence (#468) * adds bep to embassy startup sequence * always run postinit * Update appmgr/src/bin/embassy-init.rs Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> --- appmgr/src/bin/embassy-init.rs | 65 ++++++++++++++++++---------------- appmgr/src/sound.rs | 2 ++ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/appmgr/src/bin/embassy-init.rs b/appmgr/src/bin/embassy-init.rs index f1a6a90b4..b7efdfa6c 100644 --- a/appmgr/src/bin/embassy-init.rs +++ b/appmgr/src/bin/embassy-init.rs @@ -115,15 +115,12 @@ async fn init(cfg_path: Option<&str>) -> Result<(), Error> { Ok(()) } -// BLOCKING -fn run_script_if_exists>(path: P) { - use std::process::Command; - +async fn run_script_if_exists>(path: P) { let script = path.as_ref(); if script.exists() { match Command::new("/bin/bash").arg(script).spawn() { Ok(mut c) => { - if let Err(e) = c.wait() { + if let Err(e) = c.wait().await { log::error!("Error Running {}: {}", script.display(), e) } } @@ -133,28 +130,40 @@ fn run_script_if_exists>(path: P) { } async fn inner_main(cfg_path: Option<&str>) -> Result<(), Error> { - if let Err(e) = init(cfg_path).await { - log::error!("{}", e.source); - log::debug!("{}", e.source); - embassy::sound::BEETHOVEN.play().await?; - let ctx = RecoveryContext::init(cfg_path).await?; - rpc_server!({ - command: embassy::recovery_api, - context: ctx.clone(), - status: status_fn, - middleware: [ ] - }) - .with_graceful_shutdown({ - let mut shutdown = ctx.shutdown.subscribe(); - async move { - shutdown.recv().await.expect("context dropped"); - } - }) - .await - .with_kind(embassy::ErrorKind::Network)?; - } + embassy::sound::BEP.play().await?; - Ok(()) + run_script_if_exists("/embassy-os/preinit.sh").await; + + let res = if let Err(e) = init(cfg_path).await { + (|| async { + log::error!("{}", e.source); + log::debug!("{}", e.source); + embassy::sound::BEETHOVEN.play().await?; + let ctx = RecoveryContext::init(cfg_path).await?; + rpc_server!({ + command: embassy::recovery_api, + context: ctx.clone(), + status: status_fn, + middleware: [ ] + }) + .with_graceful_shutdown({ + let mut shutdown = ctx.shutdown.subscribe(); + async move { + shutdown.recv().await.expect("context dropped"); + } + }) + .await + .with_kind(embassy::ErrorKind::Network)?; + Ok::<_, Error>(()) + })() + .await + } else { + Ok(()) + }; + + run_script_if_exists("/embassy-os/postinit.sh").await; + + res } fn main() { @@ -183,8 +192,6 @@ fn main() { }); let cfg_path = matches.value_of("config"); - run_script_if_exists("/embassy-os/preinit.sh"); - let res = { let rt = tokio::runtime::Builder::new_multi_thread() .enable_all() @@ -193,8 +200,6 @@ fn main() { rt.block_on(inner_main(cfg_path)) }; - run_script_if_exists("/embassy-os/postinit.sh"); - match res { Ok(_) => (), Err(e) => { diff --git a/appmgr/src/sound.rs b/appmgr/src/sound.rs index 99d075062..97e9edb5f 100644 --- a/appmgr/src/sound.rs +++ b/appmgr/src/sound.rs @@ -337,6 +337,8 @@ macro_rules! song { }; } +pub const BEP: Song<[(Option, TimeSlice); 1]> = song!(120, [note(A, 4, Quarter);]); + pub const MARIO_DEATH: Song<[(Option, TimeSlice); 12]> = song!(400, [ note(B, 4, Quarter); note(F, 5, Quarter);