zng_wgt_setup/lib.rs
1#![doc(html_favicon_url = "https://zng-ui.github.io/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://zng-ui.github.io/res/zng-logo.png")]
3//!
4//! Setup wizard widgets.
5//!
6//! # Crate
7//!
8#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
9#![warn(unused_extern_crates)]
10#![warn(missing_docs)]
11
12use zng_wgt_wizard::Wizard;
13
14use zng_ext_l10n::l10n;
15use zng_wgt::prelude::*;
16
17zng_wgt::enable_widget_macros!();
18
19pub mod page;
20
21/// Represents a setup operation wizard.
22#[widget($crate::SetupWizard)]
23pub struct SetupWizard(Wizard);
24impl SetupWizard {
25 fn widget_intrinsic(&mut self) {
26 widget_set! {
27 self;
28 finish_cmd_name = SETUP_OP_VAR.flat_map(|op| match op {
29 SetupOp::Install => l10n!("FINISH_CMD.name-install", "Install"),
30 SetupOp::Update => l10n!("FINISH_CMD.name-update", "Update"),
31 SetupOp::Repair => l10n!("FINISH_CMD.name-repair", "Repair"),
32 SetupOp::Uninstall => l10n!("FINISH_CMD.name-uninstall", "Uninstall"),
33 });
34 }
35 }
36}
37
38context_var! {
39 /// Operation the setup wizard is managing.
40 ///
41 /// Is `Install` by default.
42 pub static SETUP_OP_VAR: SetupOp = SetupOp::Install;
43
44 /// Unique identifier of the product being setup.
45 ///
46 /// Is the [`About::app_id`] by default.
47 ///
48 /// [`About::app_id`]: zng_env::About::app_id
49 pub static APP_ID_VAR: Txt = zng_env::about().app_id.clone();
50
51 /// Display name of the product being setup.
52 ///
53 /// Is the [`About::app`] by default.
54 ///
55 /// [`About::app`]: zng_env::About::app
56 pub static APP_NAME_VAR: Txt = zng_env::about().app.clone();
57
58 /// Display version of the product being setup.
59 ///
60 /// Is the [`About::version`] by default.
61 ///
62 /// [`About::version`]: zng_env::About::version
63 pub static APP_VERSION_VAR: Txt = zng_env::about().version.to_txt();
64
65 /// Display name of the app producer.
66 ///
67 /// Is the [`About::org`] by default.
68 ///
69 /// [`About::org`]: zng_env::About::org
70 pub static APP_ORG_VAR: Txt = zng_env::about().version.to_txt();
71
72 /// Display version of the product that is already installed.
73 ///
74 /// Is [`APP_VERSION_VAR`] by default.
75 pub static INSTALLED_VERSION_VAR: Txt = APP_VERSION_VAR;
76}
77
78/// Defines what operation the wizard is configuring and running.
79///
80/// This property sets the [`SETUP_OP_VAR`].
81#[property(CONTEXT, default(SETUP_OP_VAR), widget_impl(SetupWizard))]
82pub fn setup_op(child: impl IntoUiNode, setup_op: impl IntoVar<SetupOp>) -> UiNode {
83 with_context_var(child, SETUP_OP_VAR, setup_op)
84}
85
86/// Defines the unique identifier of the product being setup.
87///
88/// This must be a globally unique identifier. A reverse DNS name is recommended.
89///
90/// The default value is [`zng::env::about().app_id`], if the setup exe is also the product main exe
91/// this does not need to be set.
92///
93/// This property sets the [`APP_ID_VAR`].
94///
95/// [`zng::env::about().app_id`]: zng_env::About::app_id
96#[property(CONTEXT, default(APP_ID_VAR), widget_impl(SetupWizard))]
97pub fn app_id(child: impl IntoUiNode, id: impl IntoVar<Txt>) -> UiNode {
98 with_context_var(child, APP_ID_VAR, id)
99}
100
101/// Defines the display name of the product being setup.
102///
103/// The default value is [`zng::env::about().app`], if the setup exe is also the product main exe
104/// this does not need to be set.
105///
106/// This property sets the [`APP_NAME_VAR`].
107///
108/// [`zng::env::about().app`]: zng_env::About::app
109#[property(CONTEXT, default(APP_NAME_VAR), widget_impl(SetupWizard))]
110pub fn app_name(child: impl IntoUiNode, name: impl IntoVar<Txt>) -> UiNode {
111 with_context_var(child, APP_NAME_VAR, name)
112}
113
114/// Defines the display version of the product being setup.
115///
116/// The default value is [`zng::env::about().version`], if the setup exe is also the product main exe
117/// this does not need to be set.
118///
119/// This property sets the [`APP_VERSION_VAR`].
120///
121/// [`zng::env::about().version`]: zng_env::About::version
122#[property(CONTEXT, default(APP_VERSION_VAR), widget_impl(SetupWizard))]
123pub fn app_version(child: impl IntoUiNode, version: impl IntoVar<Txt>) -> UiNode {
124 with_context_var(child, APP_VERSION_VAR, version)
125}
126
127/// Defines the display name of the producer of the product being setup.
128///
129/// The default value is [`zng::env::about().org`], if the setup exe is also the product main exe
130/// this does not need to be set.
131///
132/// This property sets the [`APP_ORG_VAR`].
133///
134/// [`zng::env::about().org`]: zng_env::About::org
135#[property(CONTEXT, default(APP_ORG_VAR), widget_impl(SetupWizard))]
136pub fn app_org(child: impl IntoUiNode, org: impl IntoVar<Txt>) -> UiNode {
137 with_context_var(child, APP_ORG_VAR, org)
138}
139
140/// Defines the display version of the product that is already installed.
141///
142/// The default value is [`APP_VERSION_VAR`], must be changed for [`SetupOp::Update`].
143///
144/// This property sets the [`INSTALLED_VERSION_VAR`].
145#[property(CONTEXT, default(INSTALLED_VERSION_VAR), widget_impl(SetupWizard))]
146pub fn installed_version(child: impl IntoUiNode, version: impl IntoVar<Txt>) -> UiNode {
147 with_context_var(child, INSTALLED_VERSION_VAR, version)
148}
149
150/// Represents the operation a [`SetupWizard!`] is managing.
151///
152/// The [`SETUP_OP_VAR`] defines the operation in a context.
153///
154/// [`SetupWizard!`]: struct@SetupWizard
155#[derive(Debug, PartialEq, Eq, Clone, Copy)]
156#[non_exhaustive]
157pub enum SetupOp {
158 /// Fresh install operation.
159 Install,
160 /// Replacing install operation.
161 Update,
162 /// Replacing install operation with the same version.
163 Repair,
164 /// Uninstall operation.
165 Uninstall,
166}