diff --git a/src/app.rs b/src/app.rs index 3f7a361..a531bc0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -12,6 +12,7 @@ use gtk::{gio, glib}; use crate::config::{APP_ID, PROFILE}; use crate::modals::about::AboutDialog; use crate::modals::unsupported::UnsupportedDialog; +use crate::modals::unsupported::UnsupportedDialogOutput; pub(super) struct App { unsupported_dialog: Controller, @@ -101,7 +102,9 @@ impl SimpleComponent for App { let unsupported_dialog = UnsupportedDialog::builder() .transient_for(root) .launch(()) - .detach(); + .forward(sender.input_sender(), |msg| match msg { + UnsupportedDialogOutput::CloseApplication => AppMsg::Quit, + }); let model = Self { about_dialog, diff --git a/src/modals/unsupported.rs b/src/modals/unsupported.rs index 79200f7..67f769e 100644 --- a/src/modals/unsupported.rs +++ b/src/modals/unsupported.rs @@ -1,15 +1,21 @@ use adw::StatusPage; -use gtk::prelude::GtkWindowExt; +use gtk::prelude::{ButtonExt, GtkWindowExt}; use relm4::view; use relm4::{adw, gtk, ComponentParts, ComponentSender, SimpleComponent}; use relm4_icons::icon_name; + pub struct UnsupportedDialog {} +#[derive(Debug)] +pub enum UnsupportedDialogOutput { + CloseApplication, +} + impl SimpleComponent for UnsupportedDialog { type Init = (); type Widgets = adw::Window; type Input = (); - type Output = (); + type Output = UnsupportedDialogOutput; type Root = adw::Window; fn init_root() -> Self::Root { @@ -19,7 +25,7 @@ impl SimpleComponent for UnsupportedDialog { fn init( _: Self::Init, root: &Self::Root, - _sender: ComponentSender, + sender: ComponentSender, ) -> ComponentParts { let model = Self {}; @@ -30,16 +36,22 @@ impl SimpleComponent for UnsupportedDialog { set_resizable: false, set_default_width: 400, + StatusPage::new() { set_icon_name: Some(icon_name::ISSUE), set_title: "Missing requirements", - set_description: Some("Make sure Toolbx and Gnome Terminal are installed."), - set_child: Some(>k::Button::with_label("Goodbye!")), + set_description: Some("Make sure Toolbox and Gnome Terminal are installed."), + + #[name = "btn_close"] + gtk::Button::with_label("Goodbye!") { + connect_clicked[sender] => move |_| { + sender.output(UnsupportedDialogOutput::CloseApplication).unwrap() + }, + }, }, } } - // TODO: when dialgue closes close application - // TODO: close application on button press + ComponentParts { model, widgets } }