diff --git a/Cargo.lock b/Cargo.lock index 2f9c190..d24ac60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.44" @@ -29,6 +38,17 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -143,6 +163,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags 1.3.2", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "dtoa" version = "0.4.8" @@ -541,6 +576,7 @@ dependencies = [ "serde", "serde_any", "simplelog", + "structopt", "xml-rs 0.8.4", ] @@ -734,6 +770,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "idna" version = "0.1.5" @@ -1189,6 +1234,36 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck 0.3.3", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.80", +] + [[package]] name = "syn" version = "1.0.80" @@ -1245,6 +1320,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.30" @@ -1342,6 +1426,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + [[package]] name = "unicode-xid" version = "0.2.2" @@ -1359,6 +1449,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version-compare" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2c3050c..8780fdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ simplelog = "0.11.2" futures-channel = "0.3" lazy_static = "1.4" chrono = "0.4" +structopt = "0.3" [dev-dependencies] futures-executor = "0.3" diff --git a/src/app.rs b/src/app.rs index c2f026a..3c98ef0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -150,7 +150,7 @@ impl GPSApp { .insert(paned_name.to_string(), paned.position()); } - pub fn on_startup(application: >k::Application) { + pub fn on_startup(application: >k::Application, pipeline_desc: &String) { // Create application and error out if that fails for whatever reason let app = match GPSApp::new(application) { Ok(app) => app, @@ -160,13 +160,7 @@ impl GPSApp { } }; - // When the application is activated show the UI. This happens when the first process is - // started, and in the first process whenever a second process is started - let app_weak = app.downgrade(); - application.connect_activate(glib::clone!(@weak application => move |_| { - let app = upgrade_weak!(app_weak); - app.build_ui(&application); - })); + app.build_ui(application, pipeline_desc); let app_weak = app.downgrade(); let slider: gtk::Scale = app @@ -449,7 +443,7 @@ impl GPSApp { notebook_preview.set_current_page(Some(n_video_sink as u32)); } - pub fn build_ui(&self, application: &Application) { + pub fn build_ui(&self, application: &Application, pipeline_desc: &String) { graphbook::setup_graphbook(self); graphbook::create_graphtab(self, 0, None); @@ -514,8 +508,9 @@ impl GPSApp { &Settings::recent_pipeline_description(), &app, move |app, pipeline_desc| { - app.load_pipeline(&pipeline_desc) - .unwrap_or_else(|_| GPS_ERROR!("Unable to open file {}", pipeline_desc)); + app.load_pipeline(&pipeline_desc).unwrap_or_else(|_| { + GPS_ERROR!("Unable to open pipeline description {}", pipeline_desc) + }); Settings::set_recent_pipeline_description(&pipeline_desc); }, ); @@ -607,17 +602,22 @@ impl GPSApp { GPSUI::elements::setup_favorite_list(self); // Setup the favorite list GPSUI::elements::setup_elements_list(self); - - let _ = self - .load_graph( - Settings::graph_file_path() - .to_str() - .expect("Unable to convert to string"), - true, - ) - .map_err(|_e| { - GPS_WARN!("Unable to load default graph"); + if pipeline_desc.is_empty() { + let _ = self + .load_graph( + Settings::graph_file_path() + .to_str() + .expect("Unable to convert to string"), + true, + ) + .map_err(|_e| { + GPS_WARN!("Unable to load default graph"); + }); + } else { + self.load_pipeline(pipeline_desc).unwrap_or_else(|_| { + GPS_ERROR!("Unable to open pipeline description {}", pipeline_desc) }); + } } // Downgrade to a weak reference @@ -778,9 +778,10 @@ impl GPSApp { fn load_pipeline(&self, pipeline_desc: &str) -> anyhow::Result<()> { let graphtab = graphbook::current_graphtab(self); + let pd_parsed = pipeline_desc.replace('\\', ""); graphtab .player() - .graphview_from_pipeline_description(&graphtab.graphview(), pipeline_desc); + .graphview_from_pipeline_description(&graphtab.graphview(), &pd_parsed); Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 77c7daa..43bef24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,14 +22,29 @@ use gtk::prelude::*; use crate::app::GPSApp; use crate::common::init; +use structopt::StructOpt; + +#[derive(StructOpt, Debug)] +struct Command { + #[structopt(about = "Sets the pipeline description", default_value = "")] + pipeline: String, +} fn main() { // gio::resources_register_include!("compiled.gresource").unwrap(); init().expect("Unable to init app"); - let application = gtk::Application::new(Some(config::APP_ID), Default::default()); + let application = gtk::Application::new( + Some(config::APP_ID), + gtk::gio::ApplicationFlags::HANDLES_COMMAND_LINE, + ); application.connect_startup(|application| { - GPSApp::on_startup(application); + let args = Command::from_args(); + GPSApp::on_startup(application, &args.pipeline); }); + application.connect_command_line(|_app, _cmd_line| { + // structopt already handled arguments + 0 + }); application.run(); }