Skip to content

Commit 51e1021

Browse files
committed
👷 installer: refactor installer checks
remove excessive access to global mutable variable of the window
1 parent 6903c36 commit 51e1021

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

‎src/installer.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ struct Versions {
1818
handheld_iso_version: String,
1919
}
2020

21-
fn outdated_version_check(message: String) -> bool {
21+
fn outdated_version_check(window: &gtk::Window, message: String) -> bool {
2222
let edition_tag: String =
2323
fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".into()).trim().into();
2424
let version_tag: String =
2525
fs::read_to_string("/etc/version-tag").unwrap_or("testing".into()).trim().into();
2626

27-
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
28-
2927
if version_tag.contains("testing") {
3028
utils::show_simple_dialog(
31-
window_ref,
29+
window,
3230
gtk::MessageType::Warning,
3331
&fl!("testing-iso-warning"),
3432
message.clone(),
@@ -40,7 +38,7 @@ fn outdated_version_check(message: String) -> bool {
4038

4139
if response.is_err() {
4240
utils::show_simple_dialog(
43-
window_ref,
41+
window,
4442
gtk::MessageType::Warning,
4543
&fl!("offline-error"),
4644
message.clone(),
@@ -60,7 +58,7 @@ fn outdated_version_check(message: String) -> bool {
6058

6159
if version_tag != latest_version {
6260
utils::show_simple_dialog(
63-
window_ref,
61+
window,
6462
gtk::MessageType::Warning,
6563
&fl!("outdated-version-warning"),
6664
message.clone(),
@@ -69,7 +67,7 @@ fn outdated_version_check(message: String) -> bool {
6967
true
7068
}
7169

72-
fn edition_compat_check(message: String) -> bool {
70+
fn edition_compat_check(window: &gtk::Window, message: String) -> bool {
7371
let edition_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
7472

7573
if edition_tag == "handheld" {
@@ -85,9 +83,8 @@ fn edition_compat_check(message: String) -> bool {
8583

8684
if available_profiles.iter().any(|profile| handheld_profile_names.contains(&&profile.name))
8785
{
88-
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
8986
utils::show_simple_dialog(
90-
window_ref,
87+
window,
9188
gtk::MessageType::Warning,
9289
&fl!("unsupported-hw-warning"),
9390
message.clone(),
@@ -98,20 +95,14 @@ fn edition_compat_check(message: String) -> bool {
9895
true
9996
}
10097

101-
fn connectivity_check(message: String) -> bool {
98+
fn connectivity_check(window: &gtk::Window, message: String) -> bool {
10299
let status = match reqwest::blocking::get("https://cachyos.org") {
103100
Ok(resp) => resp.status().is_success() || resp.status().is_server_error(),
104101
_ => false,
105102
};
106103

107104
if !status {
108-
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
109-
utils::show_simple_dialog(
110-
window_ref,
111-
gtk::MessageType::Error,
112-
&fl!("offline-error"),
113-
message,
114-
);
105+
utils::show_simple_dialog(window, gtk::MessageType::Error, &fl!("offline-error"), message);
115106
return false;
116107
}
117108
true
@@ -120,13 +111,14 @@ fn connectivity_check(message: String) -> bool {
120111
pub fn launch_installer(message: String) {
121112
// Spawn child process in separate thread.
122113
std::thread::spawn(move || {
114+
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
123115
let builder = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().builder };
124116

125117
let install_btn: gtk::Button = builder.object("install").unwrap();
126118
install_btn.set_sensitive(false);
127119

128120
let checks = [connectivity_check, edition_compat_check, outdated_version_check];
129-
if !checks.iter().all(|x| x(message.clone())) {
121+
if !checks.iter().all(|x| x(window_ref, message.clone())) {
130122
// if any check failed, return
131123
info!("Some ISO check failed!");
132124
install_btn.set_sensitive(true);

0 commit comments

Comments
 (0)