Skip to content

Commit

Permalink
revert(ui): returned back tos warning to the first run window
Browse files Browse the repository at this point in the history
  • Loading branch information
krypt0nn committed Aug 19, 2023
1 parent 8057fed commit 180d2bd
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/ui/first_run/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -20,6 +21,7 @@ pub static mut MAIN_WINDOW: Option<adw::ApplicationWindow> = None;

pub struct FirstRunApp {
welcome: AsyncController<WelcomeApp>,
tos_warning: AsyncController<TosWarningApp>,
dependencies: AsyncController<DependenciesApp>,
default_paths: AsyncController<DefaultPathsApp>,
download_components: AsyncController<DownloadComponentsApp>,
Expand All @@ -36,6 +38,7 @@ pub struct FirstRunApp {
pub enum FirstRunAppMsg {
SetLoadingStatus(Option<Option<String>>),

ScrollToTosWarning,
ScrollToDependencies,
ScrollToDefaultPaths,
ScrollToDownloadComponents,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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");

Expand Down
1 change: 1 addition & 0 deletions src/ui/first_run/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
125 changes: 125 additions & 0 deletions src/ui/first_run/tos_warning.rs
Original file line number Diff line number Diff line change
@@ -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<Self>,
) -> AsyncComponentParts<Self> {
let model = Self;
let widgets = view_output!();

AsyncComponentParts { model, widgets }
}

async fn update(&mut self, msg: Self::Input, sender: AsyncComponentSender<Self>) {
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()
}
}
}
8 changes: 1 addition & 7 deletions src/ui/first_run/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use relm4::component::*;

use adw::prelude::*;

use anime_launcher_sdk::is_available;

use crate::*;

use super::main::FirstRunAppMsg;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 180d2bd

Please sign in to comment.