Skip to content

Commit 71a676b

Browse files
committed
Don't require complete package list to install mods via URL protocol
Check the existence of the target package and version directly from the IndexedDB cache. After the change the Manager component no longer needs access to the complete package list of the selected community.
1 parent 80b3cbf commit 71a676b

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

src/model/ThunderstoreCombo.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
import ThunderstoreMod from './ThunderstoreMod';
22
import R2Error from './errors/R2Error';
33
import ThunderstoreVersion from './ThunderstoreVersion';
4+
import * as PackageDb from '../r2mm/manager/PackageDexieStore';
45

56
export default class ThunderstoreCombo {
67

78
private mod: ThunderstoreMod = new ThunderstoreMod();
89
private version: ThunderstoreVersion = new ThunderstoreVersion();
910

10-
public static fromProtocol(protocol: string, modList: ThunderstoreMod[]): ThunderstoreCombo | R2Error {
11-
// Strip out protocol information
12-
const reducedProtocol = protocol.replace(new RegExp("ror2mm://v1/install/([a-zA-Z0-9]+\.)?thunderstore\.io/"), '');
13-
const information = reducedProtocol.split('/');
14-
const packageName = `${information[0]}-${information[1]}`;
15-
const packageVersion = information[2];
16-
const foundMod = modList.find((mod: ThunderstoreMod) => mod.getFullName() === packageName);
17-
if (foundMod === undefined) {
18-
return new R2Error(
19-
'Mod does not exist',
20-
`Unable to resolve ${packageName} to a suitable Thunderstore mod`,
21-
'Relaunch the manager to update the mod list'
22-
);
23-
}
24-
const foundVersion = foundMod.getVersions().find((version: ThunderstoreVersion) => version.getVersionNumber().toString() === packageVersion);
25-
if (foundVersion === undefined) {
11+
public static async fromProtocol(protocol: string, community: string): Promise<ThunderstoreCombo | R2Error> {
12+
// Remove protocol information and trailing slash, leaving the package version information.
13+
const reducedProtocol = protocol
14+
.replace(new RegExp('ror2mm://v1/install/([a-zA-Z0-9]+\.)?thunderstore\.io/'), '')
15+
.replace(new RegExp('\/$'), '');
16+
const dependencyString = reducedProtocol.split('/').join('-');
17+
const foundMod = await PackageDb.getCombosByDependencyStrings(community, [dependencyString]);
18+
19+
if (!foundMod.length) {
2620
return new R2Error(
2721
'Mod does not exist',
28-
`Unable to find version ${packageVersion} of mod ${packageName}`,
29-
'Relaunch the manager to update the mod list'
22+
`Unable to resolve ${dependencyString} to a suitable Thunderstore mod or version`,
23+
'Relaunch the manager to update the mod list. Ensure the correct game and profile is selected before opening the link.'
3024
);
3125
}
32-
const combo = new ThunderstoreCombo();
33-
combo.mod = foundMod;
34-
combo.version = foundVersion;
35-
return combo;
26+
27+
return foundMod[0];
3628
}
3729

3830
public getMod(): ThunderstoreMod {

src/pages/Manager.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ import Vue from 'vue';
141141
import Component from 'vue-class-component';
142142
import { Hero, Link, Modal, Progress } from '../components/all';
143143
144-
import ThunderstoreMod from '../model/ThunderstoreMod';
145144
import ThunderstoreCombo from '../model/ThunderstoreCombo';
146145
import ProfileModList from '../r2mm/mods/ProfileModList';
147146
import PathResolver from '../r2mm/manager/PathResolver';
@@ -214,10 +213,6 @@ import ModalCard from '../components/ModalCard.vue';
214213
return this.$store.getters['profile/activeProfile'];
215214
};
216215
217-
get thunderstoreModList(): ThunderstoreMod[] {
218-
return this.$store.state.tsMods.mods;
219-
}
220-
221216
get localModList(): ManifestV2[] {
222217
return this.$store.state.profile.modList;
223218
}
@@ -619,8 +614,9 @@ import ModalCard from '../components/ModalCard.vue';
619614
this.launchParametersModel = this.settings.getContext().gameSpecific.launchParameters;
620615
const ignoreCache = this.settings.getContext().global.ignoreCache;
621616
622-
InteractionProvider.instance.hookModInstallProtocol(async data => {
623-
const combo: ThunderstoreCombo | R2Error = ThunderstoreCombo.fromProtocol(data, this.thunderstoreModList);
617+
InteractionProvider.instance.hookModInstallProtocol(async (protocolUrl) => {
618+
const community = this.$store.state.activeGame.internalFolderName;
619+
const combo: ThunderstoreCombo | R2Error = await ThunderstoreCombo.fromProtocol(protocolUrl, community);
624620
if (combo instanceof R2Error) {
625621
this.$store.commit('error/handleError', {
626622
error: combo,

0 commit comments

Comments
 (0)