summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-08 18:32:13 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-08 18:44:24 +0100
commit8b019270a0fb90e801ca6d44cbb32e8340e371ea (patch)
treee0dd27fdfaa811733b536d1720bf6200b14f9f09
parentcbdcf2228513e3f8ef87028bbabb802558039f30 (diff)
Add passing of profile name to GUI bootup code
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--gui/src/cli.rs7
-rw-r--r--gui/src/gui/mod.rs9
-rw-r--r--gui/src/main.rs10
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<Self::Message>) {
+ fn new(name: String) -> (Self, iced::Command<Self::Message>) {
(
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(())
- },
}
}