diff --git a/src/api.rs b/src/api.rs index 114e0a5..2d95bca 100644 --- a/src/api.rs +++ b/src/api.rs @@ -8,27 +8,41 @@ pub const TOR_URL: &str = "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhh /// /// pub fn api(option: &str, sub_string: &str) -> String pub fn api(option: &str, sub_string: &str) -> String { + let mut once: bool = false; + let mut dashboard: std::process::Child; if option.ends_with("dashboard") { - print!("api:invoke dashboard {:}", option); - let _ = if cfg!(target_os = "windows") { - std::process::Command::new(format!("mempool-space_{}", option)) - //.args(["/C", sub_string]) - .spawn() - .expect("failed to execute process") - } else { - std::process::Command::new(format!("mempool-space_{}", option)) - //.arg(sub_string) - .spawn() - .expect("failed to execute process") - }; - //let result = String::from_utf8(output.stdout) - // .map_err(|non_utf8| String::from_utf8_lossy(non_utf8.as_bytes()).into_owned()) - // .unwrap(); - - //return result; - loop {} + loop { + if !once { + info!("api({:}, {:})", option, sub_string); + dashboard = if cfg!(target_os = "windows") { + std::process::Command::new(format!("mempool-space_{}", option)) + .args(["/C", "--dashboard"]) + .spawn() + .expect("failed to execute process") + } else { + std::process::Command::new(format!("mempool-space_{}", option)) + .arg("--dashboard") + .spawn() + .expect("failed to execute process") + }; - //std::process::exit(0); + let stdin = dashboard.stdin.take(); + let stdout = dashboard.stdout.take(); + let stderr = dashboard.stderr.take(); + let result = dashboard.wait(); + use log::info; //, warn}; + info!("{:?}", stdin); + info!("{:?}", stdout); + info!("{:?}", stderr); + info!("{:?}", result); + once = true; + } else { + std::process::exit(0); + } + } + } + if once { + std::process::exit(0); } let output = if cfg!(target_os = "windows") { diff --git a/src/bin/mempool-space_dashboard/src/app.rs b/src/bin/mempool-space_dashboard/src/app.rs index 258f20d..3a3d010 100644 --- a/src/bin/mempool-space_dashboard/src/app.rs +++ b/src/bin/mempool-space_dashboard/src/app.rs @@ -21,6 +21,7 @@ pub struct App { pub config: Config, pub tick_rate: f64, pub frame_rate: f64, + pub dashboard: bool, pub components: Vec>, pub should_quit: bool, pub should_suspend: bool, @@ -29,7 +30,7 @@ pub struct App { } impl App { - pub fn new(tick_rate: f64, frame_rate: f64) -> Result { + pub fn new(tick_rate: f64, frame_rate: f64, dashboard: bool) -> Result { let home = Home::new(); let fps = FpsCounter::new(); let config = Config::new()?; @@ -37,6 +38,7 @@ impl App { Ok(Self { tick_rate, frame_rate, + dashboard, components: vec![Box::new(home), Box::new(fps)], should_quit: false, should_suspend: false, diff --git a/src/bin/mempool-space_dashboard/src/cli.rs b/src/bin/mempool-space_dashboard/src/cli.rs index 454f249..438c5b2 100644 --- a/src/bin/mempool-space_dashboard/src/cli.rs +++ b/src/bin/mempool-space_dashboard/src/cli.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use clap::Parser; +use clap::{ArgAction, Parser}; use crate::utils::version; @@ -24,4 +24,13 @@ pub struct Cli { default_value_t = 13.0 )] pub frame_rate: f64, + #[arg( + short, + long, + value_name = "DASHBOARD", + help = "Invoked from mempool-space --dashboard", + default_value_t = false, + action=ArgAction::SetTrue + )] + pub dashboard: bool, } diff --git a/src/bin/mempool-space_dashboard/src/main.rs b/src/bin/mempool-space_dashboard/src/main.rs index f1ebccd..95518c1 100644 --- a/src/bin/mempool-space_dashboard/src/main.rs +++ b/src/bin/mempool-space_dashboard/src/main.rs @@ -26,7 +26,7 @@ async fn tokio_main() -> Result<()> { initialize_panic_handler()?; let args = Cli::parse(); - let mut app = App::new(args.tick_rate, args.frame_rate)?; + let mut app = App::new(args.tick_rate, args.frame_rate, args.dashboard)?; app.run().await?; Ok(()) @@ -35,7 +35,7 @@ async fn tokio_main() -> Result<()> { #[tokio::main] async fn main() -> Result<()> { if let Err(e) = tokio_main().await { - eprintln!("{} error: Something went wrong", env!("CARGO_PKG_NAME")); + eprintln!("{} error: tokio_main().await", env!("CARGO_PKG_NAME")); Err(e) } else { Ok(())