Skip to content

Commit c91ce7a

Browse files
committed
feat: add outdated ISO version check
Signed-off-by: SoulHarsh007 <[email protected]>
1 parent 59647a4 commit c91ce7a

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ gtk = { version = "0.18", default-features = false }
1919
gio = { version = "0.20", default-features = false }
2020
gdk-pixbuf = "0.20"
2121
glib = { default-features = false, version = "0.20" }
22-
serde = { version = "1", default-features = false }
22+
serde = { version = "1", features = ["derive"] }
2323
serde_json = "1"
24-
reqwest = { version = "0.12", features = ["blocking"] }
24+
reqwest = { version = "0.12", features = ["blocking", "json"] }
2525
unic-langid = "0.9"
2626
phf = { version = "0.11", features = ["macros"], default-features = false }
2727
chwd = { git = "https://github.com/CachyOS/chwd", rev = "d7e7e65c5c2c0ffe0434adad9a0016617d1f8bb7", version = "1.10.0" }

i18n/en/cachyos_hello.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ calamares-install-type = Calamares install type
7979
# Main Page (body)
8080
offline-error = Unable to start online installation! No internet connection
8181
unsupported-hw-warning = You are attempting to install on hardware not supported by the current ISO, your installation will not be eligible for support
82+
outdated-version-warning = You are using an older version of CachyOS ISO, please consider using latest version for installations
8283
tweaksbrowser-label = Apps/Tweaks
8384
appbrowser-label = Install Apps
8485
launch-start-label = Launch at start

src/main.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,44 @@ static G_SAVE_JSON: Lazy<Mutex<serde_json::Value>> = Lazy::new(|| {
4141
});
4242
static mut G_HELLO_WINDOW: Option<Arc<HelloWindow>> = None;
4343

44-
fn version_compat_check(message: String) {
45-
let version_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
44+
#[derive(serde::Deserialize)]
45+
struct Versions {
46+
#[serde(rename = "desktopISOVersion")]
47+
desktop_iso_version: String,
48+
#[serde(rename = "handheldISOVersion")]
49+
handheld_iso_version: String,
50+
}
51+
52+
fn outdated_version_check(message: String) {
53+
let edition_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
54+
let version_tag = fs::read_to_string("/etc/version-tag").unwrap_or_default();
55+
56+
let versions = reqwest::blocking::get("https://cachyos.org/versions.json")
57+
.unwrap()
58+
.json::<Versions>()
59+
.unwrap();
60+
61+
let latest_version = if edition_tag == "desktop" {
62+
versions.desktop_iso_version
63+
} else {
64+
versions.handheld_iso_version
65+
};
66+
67+
if version_tag != latest_version {
68+
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
69+
show_simple_dialog(
70+
window_ref,
71+
gtk::MessageType::Warning,
72+
&fl!("outdated-version-warning"),
73+
message.clone(),
74+
);
75+
}
76+
}
77+
78+
fn edition_compat_check(message: String) {
79+
let edition_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
4680

47-
if version_tag == "handheld" {
81+
if edition_tag == "handheld" {
4882
let profiles_path =
4983
format!("{}/handhelds/profiles.toml", chwd::consts::CHWD_PCI_CONFIG_DIR);
5084

@@ -511,19 +545,20 @@ fn on_action_clicked(param: &[glib::Value]) -> Option<glib::Value> {
511545
let widget = param[0].get::<gtk::Widget>().unwrap();
512546
match widget.widget_name().as_str() {
513547
"install" => {
514-
version_compat_check(fl!("calamares-install-type"));
548+
edition_compat_check(fl!("calamares-install-type"));
549+
outdated_version_check(fl!("calamares-install-type"));
515550
quick_message(fl!("calamares-install-type"));
516551
None
517-
}
552+
},
518553
"autostart" => {
519554
let action = widget.downcast::<gtk::Switch>().unwrap();
520555
set_autostart(action.is_active());
521556
None
522-
}
557+
},
523558
_ => {
524559
show_about_dialog();
525560
None
526-
}
561+
},
527562
}
528563
}
529564

0 commit comments

Comments
 (0)