Skip to content

Commit

Permalink
Merge pull request #1289 from ebkr/downloadmodmodal-refactoring
Browse files Browse the repository at this point in the history
DownloadModModal refactoring
  • Loading branch information
anttimaki authored Apr 15, 2024
2 parents d2f63f3 + 52ed2bc commit dd003ba
Showing 1 changed file with 41 additions and 48 deletions.
89 changes: 41 additions & 48 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ import { Progress } from '../all';
import Game from '../../model/game/Game';
import ConflictManagementProvider from '../../providers/generic/installing/ConflictManagementProvider';
interface DownloadProgress {
assignId: number;
initialMods: string[];
modName: string;
progress: number;
failed: boolean;
}
let assignId = 0;
@Component({
Expand All @@ -124,12 +132,12 @@ let assignId = 0;
export default class DownloadModModal extends Vue {
versionNumbers: string[] = [];
downloadObject: any | null = null;
downloadObject: DownloadProgress | null = null;
downloadingMod: boolean = false;
selectedVersion: string | null = null;
currentVersion: string | null = null;
static allVersions: [number, any][] = [];
static allVersions: [number, DownloadProgress][] = [];
get activeGame(): Game {
return this.$store.state.activeGame;
Expand Down Expand Up @@ -178,8 +186,9 @@ let assignId = 0;
try {
await DownloadModModal.installModAfterDownload(profile, combo.getMod(), combo.getVersion());
} catch (e) {
const err: Error = e as Error;
return new R2Error(`Failed to install mod [${combo.getMod().getFullName()}]`, err.message, null);
return reject(
R2Error.fromThrownValue(e, `Failed to install mod [${combo.getMod().getFullName()}]`)
);
}
}
const modList = await ProfileModList.getModList(profile);
Expand Down Expand Up @@ -280,32 +289,12 @@ let assignId = 0;
assignId: currentAssignId,
failed: false,
}
if (this.downloadObject.assignId === currentAssignId) {
if (this.downloadObject!.assignId === currentAssignId) {
this.downloadObject = Object.assign({}, obj);
}
this.$set(DownloadModModal.allVersions, assignIndex, [currentAssignId, obj]);
}
}, async (downloadedMods: ThunderstoreCombo[]) => {
ProfileModList.requestLock(async () => {
for (const combo of downloadedMods) {
try {
await DownloadModModal.installModAfterDownload(this.profile, combo.getMod(), combo.getVersion());
} catch (e) {
const err: Error = e as Error;
return new R2Error(`Failed to install mod [${combo.getMod().getFullName()}]`, err.message, null);
}
}
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.profile);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.profile);
if (err instanceof R2Error) {
this.$store.commit('error/handleError', err);
}
}
});
});
}, this.downloadCompletedCallback);
}
downloadHandler(tsMod: ThunderstoreMod, tsVersion: ThunderstoreVersion) {
Expand Down Expand Up @@ -341,35 +330,39 @@ let assignId = 0;
assignId: currentAssignId,
failed: false,
}
if (this.downloadObject.assignId === currentAssignId) {
if (this.downloadObject!.assignId === currentAssignId) {
this.downloadObject = Object.assign({}, obj);
}
this.$set(DownloadModModal.allVersions, assignIndex, [currentAssignId, obj]);
}
}, async (downloadedMods: ThunderstoreCombo[]) => {
ProfileModList.requestLock(async () => {
for (const combo of downloadedMods) {
try {
await DownloadModModal.installModAfterDownload(this.profile, combo.getMod(), combo.getVersion());
} catch (e) {
const err: Error = e as Error;
return new R2Error(`Failed to install mod [${combo.getMod().getFullName()}]`, err.message, null);
}
}
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.profile);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.profile);
if (err instanceof R2Error) {
this.$store.commit('error/handleError', err);
}
}
});
});
}, this.downloadCompletedCallback);
}, 1);
}
async downloadCompletedCallback(downloadedMods: ThunderstoreCombo[]) {
ProfileModList.requestLock(async () => {
for (const combo of downloadedMods) {
try {
await DownloadModModal.installModAfterDownload(this.profile, combo.getMod(), combo.getVersion());
} catch (e) {
this.downloadingMod = false;
const err = R2Error.fromThrownValue(e, `Failed to install mod [${combo.getMod().getFullName()}]`);
this.$store.commit('error/handleError', err);
return;
}
}
this.downloadingMod = false;
const modList = await ProfileModList.getModList(this.profile);
if (!(modList instanceof R2Error)) {
await this.$store.dispatch('profile/updateModList', modList);
const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.profile);
if (err instanceof R2Error) {
this.$store.commit('error/handleError', err);
}
}
});
}
static async installModAfterDownload(profile: Profile, mod: ThunderstoreMod, version: ThunderstoreVersion): Promise<R2Error | void> {
return new Promise(async (resolve, reject) => {
const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(mod, version);
Expand Down

0 comments on commit dd003ba

Please sign in to comment.