diff --git a/Cargo.toml b/Cargo.toml index 399e9e0..8e12235 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,21 +16,14 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" csv = "1.1" jql = { version = "4", default-features = false } -rfd = "0.9" eframe = { version = "0.19", features = ["persistence"] } -tokio = { version = "1", features = ["full"] } -clap = { version = "4", features = ["derive"] } futures = "0.3" -sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "sqlx-postgres", "macros" ] } reqwest = { version = "0.11", features = ["json"] } - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +sea-orm = { version = "0.10", features = [ "runtime-tokio-rustls", "sqlx-sqlite", "sqlx-postgres", "macros" ] } +clap = { version = "4", features = ["derive"] } +tokio = { version = "1", features = ["full"] } tracing-subscriber = "0.3" ctrlc = "3.2.3" -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = "0.1.6" -tracing-wasm = "0.2" - [profile.dev.package."*"] opt-level = 3 diff --git a/src/gui/mod.rs b/src/gui/mod.rs index b5699e1..9552436 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -44,6 +44,7 @@ pub struct App { impl App { pub fn new( _cc: &eframe::CreationContext, + initial_uri: Option, db_uri_tx: mpsc::Sender, interval: i64, view: AppStateView, @@ -51,9 +52,14 @@ impl App { logger_view: watch::Receiver>, ) -> Self { let panels = view.panels.borrow().clone(); + if let Some(initial_uri) = &initial_uri { + if let Err(e) = db_uri_tx.blocking_send(initial_uri.clone()) { + error!(target: "app", "Could not send initial uri: {:?}", e); + } + } Self { db_uri_tx, interval, panels, width_tx, view, logger_view, - db_uri: "".into(), + db_uri: initial_uri.unwrap_or("".into()), buffer_source: entities::sources::Model::default(), buffer_metric: entities::metrics::Model::default(), last_redraw: 0, diff --git a/src/main.rs b/src/main.rs index 2b9ca57..7dbc5e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,21 +52,12 @@ enum Mode { }, /// Run as foreground user interface displaying collected data GUI { - + /// Immediately connect to this database on startup + #[arg(short, long)] + db_uri: Option, }, } -// When compiling for web: -#[cfg(target_arch = "wasm32")] -fn setup_tracing(_layer: Option) { - // Make sure panics are logged using `console.error`. - console_error_panic_hook::set_once(); - // Redirect tracing to console.log and friends: - tracing_wasm::set_as_global_default(); -} - -// When compiling natively: -#[cfg(not(target_arch = "wasm32"))] fn setup_tracing(layer: Option) { let sub = tracing_subscriber::registry() .with(LevelFilter::INFO) @@ -146,7 +137,7 @@ fn main() { worker.join().expect("Failed joining worker thread"); }, - Mode::GUI { } => { + Mode::GUI { db_uri } => { let (uri_tx, uri_rx) = mpsc::channel(10); let (width_tx, width_rx) = watch::channel(0); @@ -226,6 +217,7 @@ fn main() { Box::new( App::new( cc, + db_uri, uri_tx, args.interval as i64, view,