diff --git a/src/ui/first_run/main.rs b/src/ui/first_run/main.rs index 1adb563b..96e54946 100644 --- a/src/ui/first_run/main.rs +++ b/src/ui/first_run/main.rs @@ -9,6 +9,7 @@ use anime_launcher_sdk::components::loader::ComponentsLoader; use crate::*; use super::welcome::*; +use super::tos_warning::*; use super::dependencies::*; use super::default_paths::*; use super::download_components::*; @@ -20,6 +21,7 @@ pub static mut MAIN_WINDOW: Option = None; pub struct FirstRunApp { welcome: AsyncController, + tos_warning: AsyncController, dependencies: AsyncController, default_paths: AsyncController, download_components: AsyncController, @@ -36,6 +38,7 @@ pub struct FirstRunApp { pub enum FirstRunAppMsg { SetLoadingStatus(Option>), + ScrollToTosWarning, ScrollToDependencies, ScrollToDefaultPaths, ScrollToDownloadComponents, @@ -94,6 +97,7 @@ impl SimpleComponent for FirstRunApp { set_allow_scroll_wheel: false, append = model.welcome.widget(), + append = model.tos_warning.widget(), append = model.dependencies.widget(), append = model.default_paths.widget(), append = model.download_components.widget(), @@ -127,6 +131,10 @@ impl SimpleComponent for FirstRunApp { .launch(()) .forward(sender.input_sender(), std::convert::identity), + tos_warning: TosWarningApp::builder() + .launch(()) + .forward(sender.input_sender(), std::convert::identity), + dependencies: DependenciesApp::builder() .launch(()) .forward(sender.input_sender(), std::convert::identity), @@ -174,6 +182,12 @@ impl SimpleComponent for FirstRunApp { self.loading = status; } + FirstRunAppMsg::ScrollToTosWarning => { + self.title = tr!("tos-violation-warning"); + + self.carousel.scroll_to(self.tos_warning.widget(), true); + } + FirstRunAppMsg::ScrollToDependencies => { self.title = tr!("dependencies"); diff --git a/src/ui/first_run/mod.rs b/src/ui/first_run/mod.rs index 15af78c1..b917b5de 100644 --- a/src/ui/first_run/mod.rs +++ b/src/ui/first_run/mod.rs @@ -1,5 +1,6 @@ pub mod main; pub mod welcome; +pub mod tos_warning; pub mod dependencies; pub mod default_paths; pub mod download_components; diff --git a/src/ui/first_run/tos_warning.rs b/src/ui/first_run/tos_warning.rs new file mode 100644 index 00000000..f5a475fb --- /dev/null +++ b/src/ui/first_run/tos_warning.rs @@ -0,0 +1,125 @@ +use relm4::prelude::*; +use relm4::component::*; + +use adw::prelude::*; + +use anime_launcher_sdk::is_available; + +use crate::*; + +use super::main::FirstRunAppMsg; + +use super::main::MAIN_WINDOW; + +pub struct TosWarningApp; + +#[derive(Debug, Clone)] +pub enum TosWarningAppMsg { + Continue, + Exit +} + +#[relm4::component(async, pub)] +impl SimpleAsyncComponent for TosWarningApp { + type Init = (); + type Input = TosWarningAppMsg; + type Output = FirstRunAppMsg; + + view! { + adw::PreferencesPage { + set_hexpand: true, + + add = &adw::PreferencesGroup { + set_valign: gtk::Align::Center, + set_vexpand: true, + + gtk::Label { + set_label: &tr!("tos-violation-warning"), + add_css_class: "title-1" + } + }, + + add = &adw::PreferencesGroup { + gtk::Label { + set_label: &tr!("tos-violation-warning-message"), + set_wrap: true, + set_selectable: true + } + }, + + add = &adw::PreferencesGroup { + set_valign: gtk::Align::Center, + set_vexpand: true, + + gtk::Box { + set_orientation: gtk::Orientation::Horizontal, + set_halign: gtk::Align::Center, + set_spacing: 8, + + gtk::Button { + set_label: &tr!("continue"), + set_css_classes: &["suggested-action", "pill"], + + connect_clicked => TosWarningAppMsg::Continue + }, + + gtk::Button { + set_label: &tr!("exit"), + add_css_class: "pill", + + connect_clicked => TosWarningAppMsg::Exit + } + } + } + } + } + + async fn init( + _init: Self::Init, + root: Self::Root, + _sender: AsyncComponentSender, + ) -> AsyncComponentParts { + let model = Self; + let widgets = view_output!(); + + AsyncComponentParts { model, widgets } + } + + async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender) { + match msg { + #[allow(unused_must_use)] + TosWarningAppMsg::Continue => { + let dialog = adw::MessageDialog::new( + unsafe { MAIN_WINDOW.as_ref() }, + Some(&tr!("tos-dialog-title")), + Some(&tr!("tos-dialog-message")) + ); + + dialog.add_responses(&[ + ("exit", &tr!("exit")), + ("continue", &tr!("agree")) + ]); + + dialog.connect_response(None, move |_, response| { + match response { + "exit" => relm4::main_application().quit(), + + "continue" => { + if is_available("git") && is_available("xdelta3") { + sender.output(Self::Output::ScrollToDefaultPaths); + } else { + sender.output(Self::Output::ScrollToDependencies); + } + } + + _ => unreachable!() + } + }); + + dialog.show(); + } + + TosWarningAppMsg::Exit => relm4::main_application().quit() + } + } +} diff --git a/src/ui/first_run/welcome.rs b/src/ui/first_run/welcome.rs index 63b8d759..2a0c9646 100644 --- a/src/ui/first_run/welcome.rs +++ b/src/ui/first_run/welcome.rs @@ -3,8 +3,6 @@ use relm4::component::*; use adw::prelude::*; -use anime_launcher_sdk::is_available; - use crate::*; use super::main::FirstRunAppMsg; @@ -85,11 +83,7 @@ impl SimpleAsyncComponent for WelcomeApp { match msg { #[allow(unused_must_use)] WelcomeAppMsg::Continue => { - if is_available("git") && is_available("xdelta3") { - sender.output(Self::Output::ScrollToDefaultPaths); - } else { - sender.output(Self::Output::ScrollToDependencies); - } + sender.output(Self::Output::ScrollToTosWarning); } } }