aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-05-10 13:23:57 +0200
committerGitHub <noreply@github.com>2023-05-10 13:23:57 +0200
commitcd07d7d48b2b3d98c3d14967c3eea52aaa8f3a11 (patch)
tree80156d89ad2bce4d2e811df51581e9d77e381347 /src-tauri/src/main.rs
parent4bc48e645ce39f7cbf621c27f6a096bbef33cb45 (diff)
downloadFlightCore-cd07d7d48b2b3d98c3d14967c3eea52aaa8f3a11.tar.gz
FlightCore-cd07d7d48b2b3d98c3d14967c3eea52aaa8f3a11.zip
feat: Add button to install older Northstar version in DevView (#325)
Adds a button to DevView that allows installing older Northstar versions from Thunderstore
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index df13cfb9..b6c923e3 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -33,8 +33,25 @@ use northstar::get_northstar_version_number;
mod thunderstore;
use thunderstore::query_thunderstore_packages_api;
+use semver::Version;
+use serde::{Deserialize, Serialize};
use tauri::{Manager, Runtime};
use tokio::time::sleep;
+use ts_rs::TS;
+
+#[derive(Serialize, Deserialize, Debug, Clone, TS)]
+#[ts(export)]
+struct NorthstarThunderstoreRelease {
+ package: String,
+ version: String,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, TS)]
+#[ts(export)]
+struct NorthstarThunderstoreReleaseWrapper {
+ label: String,
+ value: NorthstarThunderstoreRelease,
+}
#[derive(Default)]
struct Counter(Arc<Mutex<i32>>);
@@ -139,6 +156,7 @@ fn main() {
github::pull_requests::apply_mods_pr,
github::pull_requests::get_launcher_download_link,
close_application,
+ get_available_northstar_versions,
])
.run(tauri::generate_context!())
{
@@ -469,6 +487,46 @@ async fn close_application<R: Runtime>(app: tauri::AppHandle<R>) -> Result<(), S
Ok(())
}
+/// Gets list of available Northstar versions from Thunderstore
+#[tauri::command]
+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 = Version::parse(&a.value.version).unwrap();
+ let b_ver = Version::parse(&b.value.version).unwrap();
+ b_ver.partial_cmp(&a_ver).unwrap() // Sort newest first
+ });
+
+ Ok(releases)
+}
+
/// Returns a serde json object of the parsed `enabledmods.json` file
pub fn get_enabled_mods(game_install: &GameInstall) -> Result<serde_json::value::Value, String> {
let enabledmods_json_path = format!("{}/R2Northstar/enabledmods.json", game_install.game_path);