diff --git a/src/app.rs b/src/app.rs index a531bc0..9243526 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ use relm4::{ actions::{RelmAction, RelmActionGroup}, adw, gtk, main_application, Component, ComponentController, ComponentParts, ComponentSender, - Controller, SimpleComponent, + Controller, }; use gtk::prelude::{ @@ -24,15 +24,21 @@ pub(super) enum AppMsg { Quit, } +#[derive(Debug)] +pub(super) enum AppCommandMsg { + PrerequisitsInstalled(bool), +} + relm4::new_action_group!(pub(super) WindowActionGroup, "win"); //relm4::new_stateless_action!(PreferencesAction, WindowActionGroup, "preferences"); relm4::new_stateless_action!(pub(super) ShortcutsAction, WindowActionGroup, "show-help-overlay"); relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about"); #[relm4::component(pub)] -impl SimpleComponent for App { +impl Component for App { type Init = (); type Input = AppMsg; + type CommandOutput = AppCommandMsg; type Output = (); type Widgets = AppWidgets; @@ -129,8 +135,10 @@ impl SimpleComponent for App { }) }; - let sender = model.unsupported_dialog.sender().clone(); - sender.send(()).unwrap(); + sender.spawn_oneshot_command(|| { + // TODO: actually check for compatibility + AppCommandMsg::PrerequisitsInstalled(true) + }); actions.add_action(shortcuts_action); actions.add_action(about_action); @@ -141,12 +149,28 @@ impl SimpleComponent for App { ComponentParts { model, widgets } } - fn update(&mut self, message: Self::Input, _sender: ComponentSender) { + fn update(&mut self, message: Self::Input, _sender: ComponentSender, _root: &Self::Root) { match message { AppMsg::Quit => main_application().quit(), } } + fn update_cmd( + &mut self, + message: Self::CommandOutput, + _sender: ComponentSender, + _: &Self::Root, + ) { + match message { + AppCommandMsg::PrerequisitsInstalled(false) => { + self.unsupported_dialog.sender().clone().send(()).unwrap() + } + AppCommandMsg::PrerequisitsInstalled(true) => { + // TODO: start process of fetching toolboxes + } + } + } + fn shutdown(&mut self, widgets: &mut Self::Widgets, _output: relm4::Sender) { widgets.save_window_size().unwrap(); }