aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/northstar
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-10-13 13:43:51 +0200
committerGitHub <noreply@github.com>2023-10-13 13:43:51 +0200
commitb58d8d138919ec911369b644d7a49c94215c77a9 (patch)
treed6442b34d339b6ebbf72d875ac6fddced47222d5 /src-tauri/src/northstar
parentb3b558dbab5ac41a64f36d36aac81f0b996101b0 (diff)
downloadFlightCore-b58d8d138919ec911369b644d7a49c94215c77a9.tar.gz
FlightCore-b58d8d138919ec911369b644d7a49c94215c77a9.zip
refactor: Move relevant functions to northstar module (#626)
* refactor: Move `get_available_northstar_versions` to northstar module * refactor: Move `check_is_northstar_outdated` to northstar module
Diffstat (limited to 'src-tauri/src/northstar')
-rw-r--r--src-tauri/src/northstar/mod.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src-tauri/src/northstar/mod.rs b/src-tauri/src/northstar/mod.rs
index a6b895db..1c2023b6 100644
--- a/src-tauri/src/northstar/mod.rs
+++ b/src-tauri/src/northstar/mod.rs
@@ -9,8 +9,99 @@ use crate::{
platform_specific::get_host_os,
GameInstall, InstallType,
};
+use crate::{NorthstarThunderstoreRelease, NorthstarThunderstoreReleaseWrapper};
use anyhow::anyhow;
+/// Gets list of available Northstar versions from Thunderstore
+#[tauri::command]
+pub async fn get_available_northstar_versions(
+) -> Result<Vec<NorthstarThunderstoreReleaseWrapper>, ()> {
+ let northstar_package_name = "Northstar";
+ let index = thermite::api::get_package_index().unwrap().to_vec();
+ let nsmod = index
+ .iter()
+ .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
+ .ok_or_else(|| panic!("Couldn't find Northstar on thunderstore???"))
+ .unwrap();
+
+ let mut releases: Vec<NorthstarThunderstoreReleaseWrapper> = vec![];
+ for (_version_string, nsmod_version_obj) in nsmod.versions.iter() {
+ let current_elem = NorthstarThunderstoreRelease {
+ package: nsmod_version_obj.name.clone(),
+ version: nsmod_version_obj.version.clone(),
+ };
+ let current_elem_wrapped = NorthstarThunderstoreReleaseWrapper {
+ label: format!(
+ "{} v{}",
+ nsmod_version_obj.name.clone(),
+ nsmod_version_obj.version.clone()
+ ),
+ value: current_elem,
+ };
+
+ releases.push(current_elem_wrapped);
+ }
+
+ releases.sort_by(|a, b| {
+ // Parse version number
+ let a_ver = semver::Version::parse(&a.value.version).unwrap();
+ let b_ver = semver::Version::parse(&b.value.version).unwrap();
+ b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first
+ });
+
+ Ok(releases)
+}
+
+/// Checks if installed Northstar version is up-to-date
+/// false -> Northstar install is up-to-date
+/// true -> Northstar install is outdated
+#[tauri::command]
+pub async fn check_is_northstar_outdated(
+ game_install: GameInstall,
+ northstar_package_name: Option<String>,
+) -> Result<bool, String> {
+ let northstar_package_name = match northstar_package_name {
+ Some(northstar_package_name) => {
+ if northstar_package_name.len() <= 1 {
+ "Northstar".to_string()
+ } else {
+ northstar_package_name
+ }
+ }
+ None => "Northstar".to_string(),
+ };
+
+ let index = match thermite::api::get_package_index() {
+ Ok(res) => res.to_vec(),
+ Err(err) => return Err(format!("Couldn't check if Northstar up-to-date: {err}")),
+ };
+ let nmod = index
+ .iter()
+ .find(|f| f.name.to_lowercase() == northstar_package_name.to_lowercase())
+ .expect("Couldn't find Northstar on thunderstore???");
+ // .ok_or_else(|| anyhow!("Couldn't find Northstar on thunderstore???"))?;
+
+ let version_number = match get_northstar_version_number(game_install) {
+ Ok(version_number) => version_number,
+ Err(err) => {
+ log::warn!("{}", err);
+ // If we fail to get new version just assume we are up-to-date
+ return Err(err);
+ }
+ };
+
+ // Release candidate version numbers are different between `mods.json` and Thunderstore
+ let version_number = crate::convert_release_candidate_number(version_number);
+
+ if version_number != nmod.latest {
+ log::info!("Installed Northstar version outdated");
+ Ok(true)
+ } else {
+ log::info!("Installed Northstar version up-to-date");
+ Ok(false)
+ }
+}
+
/// Check version number of a mod
pub fn check_mod_version_number(path_to_mod_folder: &str) -> Result<String, anyhow::Error> {
let data = std::fs::read_to_string(format!("{path_to_mod_folder}/mod.json"))?;