Skip to main content

zng_wgt_setup/
page.rs

1//! Common setup pages.
2
3mod welcome;
4pub use welcome::WelcomePage;
5
6mod install_dir;
7pub use install_dir::InstallDirPage;
8
9mod eula;
10pub use eula::{EulaPage, EulaTxt};
11
12mod status;
13pub use status::{StatusPage, StatusTaskInfoFnArgs};
14
15mod finish;
16pub use finish::{FinishAction, FinishPage};
17
18mod failed;
19pub use failed::{FailedPage, FailedTaskInfoFnArgs};
20
21mod optional_tasks;
22pub use optional_tasks::{OptionalTask, OptionalTaskGroup, OptionalTasksPage};
23
24use zng_ext_l10n::l10n;
25use zng_ext_setup::task::{SetupTask, TaskTypeId};
26use zng_wgt::prelude::*;
27
28use crate::{SETUP_OP_VAR, SetupOp};
29
30/// Represents display info about a setup task component of a setup operation.
31#[derive(Clone, Debug, PartialEq)]
32#[non_exhaustive]
33pub struct TaskInfo {
34    /// The id is [`SetupTask::task_type_id`] and task instance name.
35    pub id: (TaskTypeId, Txt),
36
37    /// Short description of the task.
38    pub info: VarEq<Txt>,
39}
40impl TaskInfo {
41    /// New with short description.
42    pub fn new(task_type_id: impl Into<TaskTypeId>, task_instance_name: impl Into<Txt>, info: impl IntoVar<Txt>) -> Self {
43        Self {
44            id: (task_type_id.into(), task_instance_name.into()),
45            info: VarEq(info.into_var()),
46        }
47    }
48
49    /// Get display info for common setup task types.
50    pub fn try_from_type(task_type_id: impl Into<TaskTypeId>, task_instance_name: impl Into<Txt>) -> Option<Self> {
51        Self::try_from_ty_impl((task_type_id.into(), task_instance_name.into()))
52    }
53    fn try_from_ty_impl(id: (TaskTypeId, Txt)) -> Option<Self> {
54        if id.0 == zng_ext_setup::task::ExtractTar::task_type_id() || id.0 == zng_ext_setup::task::CopyCurrentExe::task_type_id() {
55            let info = SETUP_OP_VAR.flat_map(|op| match op {
56                SetupOp::Install | SetupOp::Update | SetupOp::Repair => l10n!("status/default-info.extract-files", "Extract files"),
57                SetupOp::Uninstall => l10n!("status/default-info.remove-files", "Remove files"),
58            });
59            return Some(TaskInfo { id, info: VarEq(info) });
60        }
61
62        #[cfg(any(windows, target_os = "linux"))]
63        if id.0 == zng_ext_setup::task::CreateShortcut::task_type_id() {
64            let info = SETUP_OP_VAR.flat_map(|op| match op {
65                SetupOp::Install | SetupOp::Update | SetupOp::Repair => l10n!("status/default-info.create-shortcut", "Create shortcut"),
66                SetupOp::Uninstall => l10n!("status/default-info.remove-shortcut", "Remove shortcut"),
67            });
68            return Some(TaskInfo { id, info: VarEq(info) });
69        }
70
71        #[cfg(windows)]
72        if id.0 == zng_ext_setup::task::RegisterUninstaller::task_type_id() {
73            let info = SETUP_OP_VAR.flat_map(|op| match op {
74                SetupOp::Install | SetupOp::Update | SetupOp::Repair => {
75                    l10n!("status/default-info.register-uninstaller", "Register uninstaller")
76                }
77                SetupOp::Uninstall => l10n!("status/default-info.unregister-uninstaller", "Unregister uninstaller"),
78            });
79            return Some(TaskInfo { id, info: VarEq(info) });
80        }
81
82        None
83    }
84}