aboutsummaryrefslogtreecommitdiff
path: root/src-vue/src/utils/thunderstore
diff options
context:
space:
mode:
authorRémy Raes <contact@remyraes.com>2023-06-11 01:17:41 +0200
committerGitHub <noreply@github.com>2023-06-11 01:17:41 +0200
commit7254c28aaf5e890114ec5726ad4869fbab44d776 (patch)
tree12bc693794dbcf8f06e260495960014a4d68aced /src-vue/src/utils/thunderstore
parentf0edbfb315304dae1386bd5a10ce7fc6bd841043 (diff)
downloadFlightCore-7254c28aaf5e890114ec5726ad4869fbab44d776.tar.gz
FlightCore-7254c28aaf5e890114ec5726ad4869fbab44d776.zip
feat: Show outdated Thunderstore mods first (#385)
* feat: add isThunderstoreModOutdated method to utils * feat: display a badge on menu if there are some outdated thunderstore mods * feat: always display outdated mods first * feat: fetch Thunderstore mods on mods view mount To display the count of outdated Thunderstore mods on mods main page, we need to fetch them. * style: Update src-vue/src/components/ModsMenu.vue * style: Update src-vue/src/utils/thunderstore/version.ts * style: Update src-vue/src/views/mods/ThunderstoreModsView.vue * docs: improve outdated mods comment * docs: add comment regarding versions ordering
Diffstat (limited to 'src-vue/src/utils/thunderstore')
-rw-r--r--src-vue/src/utils/thunderstore/version.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src-vue/src/utils/thunderstore/version.ts b/src-vue/src/utils/thunderstore/version.ts
new file mode 100644
index 00000000..a111e08c
--- /dev/null
+++ b/src-vue/src/utils/thunderstore/version.ts
@@ -0,0 +1,33 @@
+import {ThunderstoreMod} from "../../../../src-tauri/bindings/ThunderstoreMod";
+import {NorthstarMod} from "../../../../src-tauri/bindings/NorthstarMod";
+import {store} from "../../plugins/store";
+
+/**
+ * Strips off a Thunderstore dependency string from its version
+ * (e.g. "taskinoz-WallrunningTitans-1.0.0" to
+ * "taskinoz-WallrunningTitans").
+ **/
+function getThunderstoreDependencyStringPrefix(dependency: string): string {
+ const dependencyStringMembers = dependency.split('-');
+ return `${dependencyStringMembers[0]}-${dependencyStringMembers[1]}`;
+}
+
+function isThunderstoreModOutdated(mod: ThunderstoreMod): boolean {
+ // Ensure mod is up-to-date.
+ const tsModPrefix = getThunderstoreDependencyStringPrefix(mod.versions[0].full_name);
+ const matchingMods: NorthstarMod[] = store.state.installed_mods.filter((mod: NorthstarMod) => {
+ if (!mod.thunderstore_mod_string) return false;
+ return getThunderstoreDependencyStringPrefix(mod.thunderstore_mod_string!) === tsModPrefix;
+ });
+ if (matchingMods.length !== 0) {
+ // There shouldn't be several mods with same dependency string, but we never know...
+ const matchingMod = matchingMods[0];
+ // A mod is outdated if its dependency strings differs from Thunderstore dependency string
+ // (no need for semver check here).
+ // This assumes mod versions list is sorted from newest to oldest version.
+ return matchingMod.thunderstore_mod_string !== mod.versions[0].full_name;
+ }
+ return false;
+}
+
+export { isThunderstoreModOutdated };