diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-05-10 13:23:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 13:23:57 +0200 |
commit | cd07d7d48b2b3d98c3d14967c3eea52aaa8f3a11 (patch) | |
tree | 80156d89ad2bce4d2e811df51581e9d77e381347 | |
parent | 4bc48e645ce39f7cbf621c27f6a096bbef33cb45 (diff) | |
download | FlightCore-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
-rw-r--r-- | src-tauri/Cargo.lock | 15 | ||||
-rw-r--r-- | src-tauri/Cargo.toml | 1 | ||||
-rw-r--r-- | src-tauri/bindings/NorthstarThunderstoreRelease.ts | 3 | ||||
-rw-r--r-- | src-tauri/bindings/NorthstarThunderstoreReleaseWrapper.ts | 4 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 58 | ||||
-rw-r--r-- | src-vue/src/views/DeveloperView.vue | 64 |
6 files changed, 138 insertions, 7 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6e02854f..aec72631 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -101,6 +101,7 @@ dependencies = [ "pretty_env_logger", "regex", "reqwest", + "semver 1.0.17", "sentry", "sentry-log", "serde", @@ -3395,7 +3396,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.16", + "semver 1.0.17", ] [[package]] @@ -3556,9 +3557,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" dependencies = [ "serde", ] @@ -4209,7 +4210,7 @@ dependencies = [ "raw-window-handle", "regex", "rfd", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde_json", "serde_repr", @@ -4243,7 +4244,7 @@ dependencies = [ "cargo_toml", "heck 0.4.1", "json-patch", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde_json", "tauri-utils", @@ -4266,7 +4267,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde_json", "sha2", @@ -4362,7 +4363,7 @@ dependencies = [ "phf 0.10.1", "proc-macro2", "quote", - "semver 1.0.16", + "semver 1.0.17", "serde", "serde_json", "serde_with", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 95df7208..df583658 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -66,6 +66,7 @@ zip-extract = "0.1.2" open = "3.2.0" # Windows API stuff winapi = "0.3.9" +semver = "1.0" [features] # by default Tauri runs in production mode diff --git a/src-tauri/bindings/NorthstarThunderstoreRelease.ts b/src-tauri/bindings/NorthstarThunderstoreRelease.ts new file mode 100644 index 00000000..4e9d5235 --- /dev/null +++ b/src-tauri/bindings/NorthstarThunderstoreRelease.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface NorthstarThunderstoreRelease { package: string, version: string, }
\ No newline at end of file diff --git a/src-tauri/bindings/NorthstarThunderstoreReleaseWrapper.ts b/src-tauri/bindings/NorthstarThunderstoreReleaseWrapper.ts new file mode 100644 index 00000000..77593816 --- /dev/null +++ b/src-tauri/bindings/NorthstarThunderstoreReleaseWrapper.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { NorthstarThunderstoreRelease } from "./NorthstarThunderstoreRelease"; + +export interface NorthstarThunderstoreReleaseWrapper { label: string, value: NorthstarThunderstoreRelease, }
\ No newline at end of file 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); diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index ab3d2ba6..59c7927f 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -31,6 +31,26 @@ Launch Northstar via Steam </el-button> + <br /> + <br /> + + <el-button type="primary" @click="getAvailableNorthstarVersions"> + Get available versions + </el-button> + + <el-select v-model="selected_ns_version" class="m-2" placeholder="Versions"> + <el-option + v-for="item in ns_versions" + :key="item.value" + :label="item.label" + :value="item" + /> + </el-select> + + <el-button type="primary" @click="installNorthstarVersion"> + Install + </el-button> + <h3>Repair:</h3> @@ -98,6 +118,7 @@ import { defineComponent } from "vue"; import { invoke } from "@tauri-apps/api"; import { GameInstall } from "../utils/GameInstall"; import { TagWrapper } from "../../../src-tauri/bindings/TagWrapper"; +import { NorthstarThunderstoreReleaseWrapper } from "../../../src-tauri/bindings/NorthstarThunderstoreReleaseWrapper"; import PullRequestsSelector from "../components/PullRequestsSelector.vue"; import { showErrorNotification, showNotification } from "../utils/ui"; import { Project } from "../../../src-tauri/bindings/Project" @@ -114,6 +135,8 @@ export default defineComponent({ first_tag: { label: '', value: { name: '' } }, second_tag: { label: '', value: { name: '' } }, ns_release_tags: [] as TagWrapper[], + ns_versions: [] as NorthstarThunderstoreReleaseWrapper[], + selected_ns_version: { label: '', value: { package: '', version: '' } } as NorthstarThunderstoreReleaseWrapper, selected_project: "FlightCore", project: [ { @@ -220,6 +243,47 @@ export default defineComponent({ showErrorNotification(error); }); }, + async getAvailableNorthstarVersions() { + await invoke<NorthstarThunderstoreReleaseWrapper[]>("get_available_northstar_versions") + .then((message) => { + this.ns_versions = message; + showNotification("Done", "Fetched all available Northstar versions"); + }) + .catch((error) => { + showErrorNotification(error); + }); + }, + async installNorthstarVersion() { + let game_install = { + game_path: this.$store.state.game_path, + install_type: this.$store.state.install_type + } as GameInstall; + + // Send notification telling the user to wait for the process to finish + const notification = showNotification( + `Installing Northstar version v${this.selected_ns_version.value.version}`, + "Please wait", + 'info', + 0 + ); + + let install_northstar_result = invoke("install_northstar_caller", { gamePath: game_install.game_path, northstarPackageName: this.selected_ns_version.value.package, versionNumber: this.selected_ns_version.value.version }); + + await install_northstar_result + .then((message) => { + // Send notification + showNotification(this.$t('generic.done'), this.$t('settings.repair.window.reinstall_success')); + this.$store.commit('checkNorthstarUpdates'); + }) + .catch((error) => { + showErrorNotification(error); + console.error(error); + }) + .finally(() => { + // Clear old notification + notification.close(); + }); + }, } }); </script> |