From 8b019270a0fb90e801ca6d44cbb32e8340e371ea Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 8 Dec 2021 18:32:13 +0100 Subject: Add passing of profile name to GUI bootup code Signed-off-by: Matthias Beyer --- gui/src/cli.rs | 7 +++++++ gui/src/gui/mod.rs | 9 +++++---- gui/src/main.rs | 10 ++++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gui/src/cli.rs b/gui/src/cli.rs index 6ebdfb9..bf81b45 100644 --- a/gui/src/cli.rs +++ b/gui/src/cli.rs @@ -8,5 +8,12 @@ pub fn app<'a>() -> App<'a> { .author(crate_authors!()) .version(crate_version!()) .about("Distributed social network, GUI frontend") + + .arg(Arg::new("name") + .index(1) + .takes_value(true) + .value_name("NAME") + .about("Profile to load the GUI for") + ) } diff --git a/gui/src/gui/mod.rs b/gui/src/gui/mod.rs index 2eb936e..c54a17a 100644 --- a/gui/src/gui/mod.rs +++ b/gui/src/gui/mod.rs @@ -46,13 +46,13 @@ enum Message { impl Application for Distrox { type Executor = iced::executor::Default; // tokio type Message = Message; - type Flags = (); + type Flags = String; - fn new(_flags: ()) -> (Self, iced::Command) { + fn new(name: String) -> (Self, iced::Command) { ( Distrox::Loading, iced::Command::perform(async { - match Profile::new_inmemory(Config::default()).await { + match Profile::new_inmemory(Config::default(), &name).await { Err(_) => Message::FailedToLoad, Ok(instance) => { Message::Loaded(Arc::new(instance)) @@ -169,7 +169,7 @@ impl Application for Distrox { } -pub fn run() -> Result<()> { +pub fn run(name: String) -> Result<()> { let settings = iced::Settings { window: iced::window::Settings { resizable: true, @@ -178,6 +178,7 @@ pub fn run() -> Result<()> { always_on_top: false, ..iced::window::Settings::default() }, + flags: name, exit_on_close_request: true, ..iced::Settings::default() }; diff --git a/gui/src/main.rs b/gui/src/main.rs index ea47a93..bfa133e 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -10,16 +10,14 @@ fn main() -> Result<()> { let matches = crate::cli::app().get_matches(); match matches.subcommand() { - None => crate::gui::run(), + None => { + let name = matches.value_of("name").map(String::from).unwrap(); // safe by clap + crate::gui::run(name) + }, Some((other, _)) => { log::error!("No subcommand {} implemented", other); Ok(()) }, - - _ => { - log::error!("Don't know what to do"); - Ok(()) - }, } } -- cgit v1.2.3