Skip to content

Commit

Permalink
Clean up the download state management Vuex store and it's usages
Browse files Browse the repository at this point in the history
  • Loading branch information
VilppeRiskidev committed Jan 8, 2025
1 parent cc472eb commit 947716b
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 172 deletions.
Binary file added src/assets/images/game_selection/Subterror.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
193 changes: 55 additions & 138 deletions src/components/views/DownloadModModal.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<div>
<div id='downloadProgressModal' :class="['modal', {'is-active':downloadingMod}]" v-if="$store.state.download.downloadObject !== null">
<div id='downloadProgressModal' :class="['modal', {'is-active':downloadingMod}]" v-if="$store.getters['download/currentDownload'] !== null">
<div class="modal-background" @click="downloadingMod = false;"></div>
<div class='modal-content'>
<div class='notification is-info'>
<h3 class='title'>Downloading {{$store.state.download.downloadObject.modName}}</h3>
<p>{{Math.floor($store.state.download.downloadObject.progress)}}% complete</p>
<h3 class='title'>Downloading {{$store.getters['download/currentDownload'].modName}}</h3>
<p>{{Math.floor($store.getters['download/currentDownload'].progress)}}% complete</p>
<Progress
:max='100'
:value='$store.state.download.downloadObject.progress'
:value="$store.getters['download/currentDownload'].progress"
:className="['is-dark']"
/>
</div>
Expand Down Expand Up @@ -61,14 +61,6 @@ import ProfileInstallerProvider from '../../providers/ror2/installing/ProfileIns
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
import ProfileModList from '../../r2mm/mods/ProfileModList';
interface DownloadProgress {
assignId: number;
initialMods: string[];
modName: string;
progress: number;
failed: boolean;
}
@Component({
components: {
DownloadModVersionSelectModal,
Expand All @@ -91,52 +83,29 @@ interface DownloadProgress {
ignoreCache: boolean,
store: Store<any>
): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
const tsMod = combo.getMod();
const tsVersion = combo.getVersion();
store.commit('download/increaseAssignId');
const currentAssignId = store.state.download.assignId;
const progressObject = {
progress: 0,
initialMods: [`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`],
modName: '',
assignId: currentAssignId,
failed: false,
};
store.commit('download/pushDownloadObjectToAllVersions', {
assignId: currentAssignId,
downloadObject: progressObject
});
const assignId = await store.dispatch(
'download/addDownload',
[`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`]
);
setTimeout(() => {
ThunderstoreDownloaderProvider.instance.download(profile.asImmutableProfile(), tsMod, tsVersion, ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
const assignIndex = store.state.download.allVersions.findIndex(([number, val]: [number, DownloadProgress]) => number === currentAssignId);
if (status === StatusEnum.FAILURE) {
if (err !== null) {
const existing = store.state.download.allVersions[assignIndex]
existing[1].failed = true;
store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, existing[1]]
});
DownloadModModal.addSolutionsToError(err);
return reject(err);
}
} else if (status === StatusEnum.PENDING) {
const obj = {
progress: progress,
initialMods: [`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`],
modName: modName,
assignId: currentAssignId,
failed: false,
try {
if (status === StatusEnum.FAILURE) {
store.commit('download/updateDownload', {assignId, failed: true});
if (err !== null) {
DownloadModModal.addSolutionsToError(err);
return reject(err);
}
} else if (status === StatusEnum.PENDING) {
store.commit('download/updateDownload', {assignId, progress, modName});
}
store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, obj]
});
} catch (e) {
return reject(e);
}
}, async (downloadedMods: ThunderstoreCombo[]) => {
ProfileModList.requestLock(async () => {
Expand Down Expand Up @@ -167,112 +136,60 @@ interface DownloadProgress {
this.closeModal();
const modsWithUpdates: ThunderstoreCombo[] = await this.$store.dispatch('profile/getCombosWithUpdates');
this.$store.commit('download/increaseAssignId');
const currentAssignId = this.$store.state.download.assignId;
const assignId = await this.$store.dispatch(
'download/addDownload',
modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().toString()})`)
);
const progressObject = {
progress: 0,
initialMods: modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().toString()})`),
modName: '',
assignId: currentAssignId,
failed: false,
};
this.$store.commit('download/setDownloadObject', progressObject);
this.$store.commit('download/pushDownloadObjectToAllVersions', {
assignId: currentAssignId,
downloadObject: progressObject
});
this.downloadingMod = true;
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(modsWithUpdates, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
const assignIndex = this.$store.state.download.allVersions.findIndex(([number, val]: [number, DownloadProgress]) => number === currentAssignId);
if (status === StatusEnum.FAILURE) {
if (err !== null) {
try {
if (status === StatusEnum.FAILURE) {
this.downloadingMod = false;
const existing = this.$store.state.download.allVersions[assignIndex];
existing[1].failed = true;
this.$store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, existing[1]]
});
DownloadModModal.addSolutionsToError(err);
this.$store.commit('error/handleError', err);
return;
}
} else if (status === StatusEnum.PENDING) {
const obj = {
progress: progress,
modName: modName,
initialMods: modsWithUpdates.map(value => `${value.getMod().getName()} (${value.getVersion().getVersionNumber().toString()})`),
assignId: currentAssignId,
failed: false,
}
if (this.$store.state.download.downloadObject!.assignId === currentAssignId) {
this.$store.commit('download/setDownloadObject', obj);
this.$store.commit('download/updateDownload', {assignId, failed: true});
if (err !== null) {
DownloadModModal.addSolutionsToError(err);
throw err;
}
} else if (status === StatusEnum.PENDING) {
this.$store.commit('download/updateDownload', {assignId, progress, modName});
}
this.$store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, obj]
});
} catch (e) {
this.$store.commit('error/handleError', e);
}
}, (downloadedMods) => {
this.downloadCompletedCallback(downloadedMods);
}, async (downloadedMods) => {
await this.downloadCompletedCallback(downloadedMods);
this.downloadingMod = false;
});
}
downloadHandler(tsMod: ThunderstoreMod, tsVersion: ThunderstoreVersion) {
async downloadHandler(tsMod: ThunderstoreMod, tsVersion: ThunderstoreVersion) {
this.closeModal();
this.$store.commit('download/increaseAssignId');
const currentAssignId = this.$store.state.download.assignId;
const assignId = await this.$store.dispatch(
'download/addDownload',
[`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`]
);
const progressObject = {
progress: 0,
initialMods: [`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`],
modName: '',
assignId: currentAssignId,
failed: false,
};
this.$store.commit('download/setDownloadObject', progressObject);
this.$store.commit('download/pushDownloadObjectToAllVersions', {
assignId: currentAssignId,
downloadObject: this.$store.state.download.downloadObject
});
this.downloadingMod = true;
setTimeout(() => {
ThunderstoreDownloaderProvider.instance.download(this.profile.asImmutableProfile(), tsMod, tsVersion, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
const assignIndex = this.$store.state.download.allVersions.findIndex(([number, val]: [number, DownloadProgress]) => number === currentAssignId);
if (status === StatusEnum.FAILURE) {
if (err !== null) {
try {
if (status === StatusEnum.FAILURE) {
this.downloadingMod = false;
const existing = this.$store.state.download.allVersions[assignIndex];
existing[1].failed = true;
this.$store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, existing[1]]
});
DownloadModModal.addSolutionsToError(err);
this.$store.commit('error/handleError', err);
return;
}
} else if (status === StatusEnum.PENDING) {
const obj = {
progress: progress,
initialMods: [`${tsMod.getName()} (${tsVersion.getVersionNumber().toString()})`],
modName: modName,
assignId: currentAssignId,
failed: false,
}
if (this.$store.state.download.downloadObject!.assignId === currentAssignId) {
this.$store.commit('download/setDownloadObject', obj);
this.$store.commit('download/updateDownload', {assignId, failed: true});
if (err !== null) {
DownloadModModal.addSolutionsToError(err);
throw err;
}
} else if (status === StatusEnum.PENDING) {
this.$store.commit('download/updateDownload', {assignId, progress, modName});
}
this.$store.commit('download/updateDownloadObject', {
assignId: assignIndex,
downloadVersion: [currentAssignId, obj]
});
} catch (e) {
this.$store.commit('error/handleError', e);
}
}, (downloadedMods) => {
this.downloadCompletedCallback(downloadedMods);
}, async (downloadedMods) => {
await this.downloadCompletedCallback(downloadedMods);
this.downloadingMod = false;
});
}, 1);
Expand Down
6 changes: 6 additions & 0 deletions src/model/game/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ export default class GameManager {
"https://thunderstore.io/c/peaks-of-yore/api/v1/package-listing-index/", EXCLUSIONS,
[new StorePlatformMetadata(StorePlatform.STEAM, "2236070")], "PeaksOfYore.png",
GameSelectionDisplayMode.VISIBLE, GameInstanceType.GAME, PackageLoader.BEPINEX, ["poy"]),

new Game("Subterror", "Subterror", "Subterror",
"Subterror", ["Subterror.exe"], "Subterror_Data",
"https://thunderstore.io/c/subterror/api/v1/package-listing-index/", EXCLUSIONS,
[new StorePlatformMetadata(StorePlatform.STEAM, "2846060")], "Subterror.png",
GameSelectionDisplayMode.VISIBLE, GameInstanceType.GAME, PackageLoader.BEPINEX, ["st"]),
];

static get activeGame(): Game {
Expand Down
12 changes: 7 additions & 5 deletions src/pages/DownloadMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</template>
<template v-else>
<div v-for="([assignId, downloadObject], index) of activeDownloads" :key="`download-progress-${index}`">
<div v-for="(downloadObject, index) of activeDownloads" :key="`download-progress-${index}`">
<div>
<div class="container margin-right">
<div class="border-at-bottom pad pad--sides">
Expand Down Expand Up @@ -42,10 +42,12 @@

<script lang="ts">
import Timeout = NodeJS.Timeout;
import { Component, Vue } from 'vue-property-decorator';
import { Hero } from '../components/all';
import Progress from '../components/Progress.vue';
import Timeout = NodeJS.Timeout;
import { DownloadProgress } from "../store/modules/DownloadModule";
@Component({
components: {
Expand All @@ -55,12 +57,12 @@ import Timeout = NodeJS.Timeout;
})
export default class DownloadMonitor extends Vue {
private refreshInterval!: Timeout;
private activeDownloads: [number, any][] = [];
private activeDownloads: DownloadProgress[] = [];
created() {
this.activeDownloads = [...this.$store.state.download.allVersions].reverse();
this.activeDownloads = [...this.$store.state.download.allDownloads].reverse();
this.refreshInterval = setInterval(() => {
this.activeDownloads = [...this.$store.state.download.allVersions].reverse();
this.activeDownloads = [...this.$store.state.download.allDownloads].reverse();
}, 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export default class InstallationRuleApplicator {
buildBepInExRules("STRAFTAT"),
buildBepInExRules("ATLYSS"),
buildBepInExRules("PeaksOfYore"),
buildBepInExRules("Subterror"),
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const VARIANTS = {
STRAFTAT: MODLOADER_PACKAGES,
ATLYSS: MODLOADER_PACKAGES,
PeaksOfYore: MODLOADER_PACKAGES,
Subterror: MODLOADER_PACKAGES,
};
// Exported separately from the definition in order to preserve the key names in the type definition.
// Otherwise this would become [key: string] and we couldn't use the game names for type hinting elsewhere.
Expand Down
Loading

0 comments on commit 947716b

Please sign in to comment.