Skip to content

Commit

Permalink
feat: add outdated ISO version check
Browse files Browse the repository at this point in the history
Signed-off-by: SoulHarsh007 <[email protected]>
  • Loading branch information
SoulHarsh007 committed Nov 6, 2024
1 parent 59647a4 commit c91ce7a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ gtk = { version = "0.18", default-features = false }
gio = { version = "0.20", default-features = false }
gdk-pixbuf = "0.20"
glib = { default-features = false, version = "0.20" }
serde = { version = "1", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.12", features = ["blocking"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
unic-langid = "0.9"
phf = { version = "0.11", features = ["macros"], default-features = false }
chwd = { git = "https://github.com/CachyOS/chwd", rev = "d7e7e65c5c2c0ffe0434adad9a0016617d1f8bb7", version = "1.10.0" }
Expand Down
1 change: 1 addition & 0 deletions i18n/en/cachyos_hello.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ calamares-install-type = Calamares install type
# Main Page (body)
offline-error = Unable to start online installation! No internet connection
unsupported-hw-warning = You are attempting to install on hardware not supported by the current ISO, your installation will not be eligible for support
outdated-version-warning = You are using an older version of CachyOS ISO, please consider using latest version for installations
tweaksbrowser-label = Apps/Tweaks
appbrowser-label = Install Apps
launch-start-label = Launch at start
Expand Down
49 changes: 42 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,44 @@ static G_SAVE_JSON: Lazy<Mutex<serde_json::Value>> = Lazy::new(|| {
});
static mut G_HELLO_WINDOW: Option<Arc<HelloWindow>> = None;

fn version_compat_check(message: String) {
let version_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
#[derive(serde::Deserialize)]
struct Versions {
#[serde(rename = "desktopISOVersion")]
desktop_iso_version: String,
#[serde(rename = "handheldISOVersion")]
handheld_iso_version: String,
}

fn outdated_version_check(message: String) {
let edition_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());
let version_tag = fs::read_to_string("/etc/version-tag").unwrap_or_default();

let versions = reqwest::blocking::get("https://cachyos.org/versions.json")
.unwrap()
.json::<Versions>()
.unwrap();

let latest_version = if edition_tag == "desktop" {
versions.desktop_iso_version
} else {
versions.handheld_iso_version
};

if version_tag != latest_version {
let window_ref = unsafe { &G_HELLO_WINDOW.as_ref().unwrap().window };
show_simple_dialog(
window_ref,
gtk::MessageType::Warning,
&fl!("outdated-version-warning"),
message.clone(),
);
}
}

fn edition_compat_check(message: String) {
let edition_tag = fs::read_to_string("/etc/edition-tag").unwrap_or("desktop".to_string());

if version_tag == "handheld" {
if edition_tag == "handheld" {
let profiles_path =
format!("{}/handhelds/profiles.toml", chwd::consts::CHWD_PCI_CONFIG_DIR);

Expand Down Expand Up @@ -511,19 +545,20 @@ fn on_action_clicked(param: &[glib::Value]) -> Option<glib::Value> {
let widget = param[0].get::<gtk::Widget>().unwrap();
match widget.widget_name().as_str() {
"install" => {
version_compat_check(fl!("calamares-install-type"));
edition_compat_check(fl!("calamares-install-type"));
outdated_version_check(fl!("calamares-install-type"));
quick_message(fl!("calamares-install-type"));
None
}
},
"autostart" => {
let action = widget.downcast::<gtk::Switch>().unwrap();
set_autostart(action.is_active());
None
}
},
_ => {
show_about_dialog();
None
}
},
}
}

Expand Down

0 comments on commit c91ce7a

Please sign in to comment.