zng_wgt_setup/page/
welcome.rs1use zng_ext_l10n::l10n;
2use zng_wgt::prelude::*;
3use zng_wgt_markdown::Markdown;
4use zng_wgt_wizard::{Page, PageArgs};
5
6use crate::{APP_NAME_VAR, APP_VERSION_VAR, INSTALLED_VERSION_VAR, SETUP_OP_VAR, SetupOp};
7
8#[non_exhaustive]
10pub struct WelcomePage {
11 pub title: Var<Txt>,
15 pub msg: Var<Txt>,
17 pub msg_extra: Var<Txt>,
19}
20impl Default for WelcomePage {
21 fn default() -> Self {
22 Self {
23 title: SETUP_OP_VAR.flat_map(|op| match op {
24 SetupOp::Install => l10n!("welcome/title.install", "Welcome to the {$app} Install Wizard", app = APP_NAME_VAR),
25 SetupOp::Update => l10n!("welcome/title.update", "Welcome to the {$app} Update Wizard", app = APP_NAME_VAR),
26 SetupOp::Repair => l10n!("welcome/title.repair", "Welcome to the {$app} Repair Wizard", app = APP_NAME_VAR),
27 SetupOp::Uninstall => l10n!(
28 "welcome/title.uninstall",
29 "Welcome to the {$app} Uninstall Wizard",
30 app = APP_NAME_VAR
31 ),
32 }),
33 msg: SETUP_OP_VAR.flat_map(|op| match op {
34 SetupOp::Install => l10n!(
35 "welcome/message.install",
36 "This will install {$app} {$version} on your computer.",
37 app = APP_NAME_VAR,
38 version = APP_VERSION_VAR,
39 ),
40 SetupOp::Update => l10n!(
41 "welcome/message.update",
42 "This will update {$app} from {$current_version} to {$new_version} on your computer.",
43 app = APP_NAME_VAR,
44 current_version = INSTALLED_VERSION_VAR,
45 new_version = APP_VERSION_VAR,
46 ),
47 SetupOp::Repair => l10n!(
48 "welcome/message.install",
49 "This will repair {$app} {$version} installation on your computer.",
50 app = APP_NAME_VAR,
51 version = APP_VERSION_VAR,
52 ),
53 SetupOp::Uninstall => l10n!(
54 "welcome/message.uninstall",
55 "This will uninstall {$app} {$version} from your your computer.",
56 app = APP_NAME_VAR,
57 version = APP_VERSION_VAR,
58 ),
59 }),
60 msg_extra: const_var("".into()),
61 }
62 }
63}
64impl WelcomePage {
65 pub fn new(msg_extra: impl IntoVar<Txt>) -> Self {
67 Self {
68 msg_extra: msg_extra.into_var(),
69 ..Self::default()
70 }
71 }
72
73 pub fn build(self) -> Page {
75 let Self { title, msg, msg_extra } = self;
76 let msg = expr_var! {
77 formatx!("## {}\n\n{}\n\n{}", #{title}, #{msg}, #{msg_extra})
78 };
79 let mut pg = Page::new(
80 "",
81 "",
82 wgt_fn!(|args: PageArgs| {
83 if !args.is_first() {
84 tracing::warn!("welcome page is not first");
85 }
86 Markdown! {
87 txt = msg.clone();
88 }
89 }),
90 );
91 pg.header = WidgetFn::nil();
92 pg
93 }
94}