Skip to content

Commit

Permalink
v0.0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan committed Sep 3, 2024
1 parent d7108a1 commit 1497176
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
52 changes: 33 additions & 19 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 3 additions & 1 deletion src/bin/mempool-space_dashboard/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct App {
pub config: Config,
pub tick_rate: f64,
pub frame_rate: f64,
pub dashboard: bool,
pub components: Vec<Box<dyn Component>>,
pub should_quit: bool,
pub should_suspend: bool,
Expand All @@ -29,14 +30,15 @@ pub struct App {
}

impl App {
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
pub fn new(tick_rate: f64, frame_rate: f64, dashboard: bool) -> Result<Self> {
let home = Home::new();
let fps = FpsCounter::new();
let config = Config::new()?;
let mode = Mode::Home;
Ok(Self {
tick_rate,
frame_rate,
dashboard,
components: vec![Box::new(home), Box::new(fps)],
should_quit: false,
should_suspend: false,
Expand Down
11 changes: 10 additions & 1 deletion src/bin/mempool-space_dashboard/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use clap::Parser;
use clap::{ArgAction, Parser};

use crate::utils::version;

Expand All @@ -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,
}
4 changes: 2 additions & 2 deletions src/bin/mempool-space_dashboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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(())
Expand Down

0 comments on commit 1497176

Please sign in to comment.