Skip to content

Commit 06886bb

Browse files
Add installationProgress to the Vuex store, update the value when installing
and display it on the UI
1 parent 79ad418 commit 06886bb

File tree

6 files changed

+38
-20
lines changed

6 files changed

+38
-20
lines changed

Diff for: src/components/mixins/DownloadMixin.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export default class DownloadMixin extends Vue {
4242
return this.$store.getters['profile/activeProfile'];
4343
}
4444
45-
async downloadCompletedCallback(downloadedMods: ThunderstoreCombo[]): Promise<void> {
45+
async downloadCompletedCallback(downloadedMods: ThunderstoreCombo[], assignId: number): Promise<void> {
4646
try {
47-
await installModsAndResolveConflicts(downloadedMods, this.profile.asImmutableProfile(), this.$store);
47+
await installModsAndResolveConflicts(downloadedMods, this.profile.asImmutableProfile(), this.$store, assignId);
4848
} catch (e) {
4949
this.$store.commit('error/handleError', R2Error.fromThrownValue(e));
5050
}

Diff for: src/components/profiles-modals/ImportProfileModal.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,20 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
203203
async importProfile(targetProfileName: string, mods: ExportMod[], zipPath: string) {
204204
this.activeStep = 'PROFILE_IS_BEING_IMPORTED';
205205
this.importPhaseDescription = 'Downloading mods: 0%';
206-
const progressCallback = (progress: number|string) => typeof progress === "number"
207-
? this.importPhaseDescription = `Downloading mods: ${Math.floor(progress)}%`
208-
: this.importPhaseDescription = progress;
206+
const progressCallback = (progressText: string) => this.importPhaseDescription = progressText;
209207
const game = this.$store.state.activeGame;
210208
const settings = this.$store.getters['settings'];
211209
const ignoreCache = settings.getContext().global.ignoreCache;
212210
const isUpdate = this.importUpdateSelection === 'UPDATE';
213211
214212
try {
215213
const comboList = await ProfileUtils.exportModsToCombos(mods, game);
216-
await ThunderstoreDownloaderProvider.instance.downloadImportedMods(comboList, ignoreCache, progressCallback);
217-
await ProfileUtils.populateImportedProfile(comboList, mods, targetProfileName, isUpdate, zipPath, progressCallback);
214+
await ThunderstoreDownloaderProvider.instance.downloadImportedMods(comboList, ignoreCache, (progress) => {
215+
progressCallback(`Downloading mods: ${Math.floor(progress)}%`)
216+
});
217+
await ProfileUtils.populateImportedProfile(comboList, mods, targetProfileName, isUpdate, zipPath, (progress) => {
218+
progressCallback(`Copying mods to profile: ${progress}%`)
219+
});
218220
} catch (e) {
219221
await this.$store.dispatch('profiles/ensureProfileExists');
220222
this.closeModal();

Diff for: src/components/views/DownloadModModal.vue

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
<div class="modal-background" @click="setIsModProgressModalOpen(false);"></div>
55
<div class='modal-content'>
66
<div class='notification is-info'>
7-
<h3 class='title'>Downloading {{$store.getters['download/currentDownload'].modName}}</h3>
8-
<p>{{Math.floor($store.getters['download/currentDownload'].downloadProgress)}}% complete</p>
7+
<h3 class='title'>Downloading and installing {{$store.getters['download/currentDownload'].modName}}</h3>
8+
<p>Downloading: {{Math.floor($store.getters['download/currentDownload'].downloadProgress)}}% complete</p>
99
<Progress
1010
:max='100'
1111
:value="$store.getters['download/currentDownload'].downloadProgress"
1212
:className="['is-dark']"
1313
/>
14+
<p v-if="$store.getters['download/currentDownload'].installationProgress">Installation: {{$store.getters['download/currentDownload'].installationProgress}}% complete</p>
15+
<p v-else>Installation: waiting for download to finish</p>
16+
<Progress
17+
:max='100'
18+
:value="$store.getters['download/currentDownload'].installationProgress"
19+
:className="['is-dark']"
20+
/>
1421
</div>
1522
</div>
1623
<button class="modal-close is-large" aria-label="close" @click="setIsModProgressModalOpen(false);"></button>
@@ -147,7 +154,7 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
147154
this.$store.commit('error/handleError', R2Error.fromThrownValue(e));
148155
return;
149156
}
150-
await this.downloadCompletedCallback(downloadedMods);
157+
await this.downloadCompletedCallback(downloadedMods, assignId);
151158
this.setIsModProgressModalOpen(false);
152159
}, 1);
153160

Diff for: src/components/views/UpdateAllInstalledModsModal.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class UpdateAllInstalledModsModal extends mixins(DownloadMixin)
6565
this.$store.commit('error/handleError', R2Error.fromThrownValue(e));
6666
}
6767
}, async (downloadedMods) => {
68-
await this.downloadCompletedCallback(downloadedMods);
68+
await this.downloadCompletedCallback(downloadedMods, assignId);
6969
this.setIsModProgressModalOpen(false);
7070
});
7171
}

Diff for: src/store/modules/DownloadModule.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface DownloadProgress {
88
initialMods: string[];
99
modName: string;
1010
downloadProgress: number;
11+
installationProgress: number;
1112
failed: boolean;
1213
}
1314

@@ -42,6 +43,7 @@ export const DownloadModule = {
4243
initialMods,
4344
modName: '',
4445
downloadProgress: 0,
46+
installationProgress: 0,
4547
failed: false,
4648
};
4749
state.allDownloads = [...state.allDownloads, downloadObject];
@@ -52,7 +54,7 @@ export const DownloadModule = {
5254
getters: <GetterTree<State, RootState>>{
5355
activeDownloadCount(state) {
5456
const active = state.allDownloads.filter(
55-
dl => !dl.failed && dl.downloadProgress < 100
57+
dl => !dl.failed && dl.downloadProgress < 100 && dl.installationProgress < 100
5658
);
5759
return active.length;
5860
},

Diff for: src/utils/ProfileUtils.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function exportModsToCombos(exportMods: ExportMod[], game: Game): P
3737
async function extractConfigsToImportedProfile(
3838
file: string,
3939
profileName: string,
40-
progressCallback: (status: string) => void
40+
progressCallback: (status: number) => void
4141
) {
4242
const zipEntries = await ZipProvider.instance.getEntries(file);
4343
const excludedFiles = ["export.r2x", "mods.yml"];
@@ -54,17 +54,20 @@ async function extractConfigsToImportedProfile(
5454
}
5555

5656
const progress = Math.floor(((index + 1) / zipEntries.length) * 100);
57-
progressCallback(`Copying configs to profile: ${progress}%`);
57+
progressCallback(progress);
5858
}
5959
}
6060

6161
export async function installModsAndResolveConflicts(
6262
downloadedMods: ThunderstoreCombo[],
6363
profile: ImmutableProfile,
64-
store: Store<any>
64+
store: Store<any>,
65+
assignId: number
6566
): Promise<void> {
6667
await ProfileModList.requestLock(async () => {
67-
const modList: ManifestV2[] = await installModsToProfile(downloadedMods, profile);
68+
const modList: ManifestV2[] = await installModsToProfile(downloadedMods, profile, undefined, (installationProgress) => {
69+
store.commit('download/updateDownload', {assignId, installationProgress});
70+
});
6871
await store.dispatch('profile/updateModList', modList);
6972
throwForR2Error(await ConflictManagementProvider.instance.resolveConflicts(modList, profile));
7073
});
@@ -79,7 +82,7 @@ export async function installModsToProfile(
7982
comboList: ThunderstoreCombo[],
8083
profile: ImmutableProfile,
8184
disabledModsOverride?: string[],
82-
progressCallback?: (status: string) => void
85+
progressCallback?: (status: number) => void
8386
): Promise<ManifestV2[]> {
8487
const profileMods = await ProfileModList.getModList(profile);
8588
if (profileMods instanceof R2Error) {
@@ -120,7 +123,7 @@ export async function installModsToProfile(
120123

121124
if (typeof progressCallback === "function") {
122125
const progress = Math.floor(((index + 1) / comboList.length) * 100);
123-
progressCallback(`Copying mods to profile: ${progress}%`);
126+
progressCallback(progress);
124127
}
125128
}
126129
} catch (e) {
@@ -200,8 +203,12 @@ export async function populateImportedProfile(
200203

201204
try {
202205
const disabledMods = exportModList.filter((m) => !m.isEnabled()).map((m) => m.getName());
203-
await installModsToProfile(comboList, profile, disabledMods, progressCallback);
204-
await extractConfigsToImportedProfile(zipPath, profile.getProfileName(), progressCallback);
206+
await installModsToProfile(comboList, profile, disabledMods, (progress) => {
207+
progressCallback(`Copying mods to profile: ${progress}%`);
208+
});
209+
await extractConfigsToImportedProfile(zipPath, profile.getProfileName(), (progress) => {
210+
progressCallback(`Copying configs to profile: ${progress}%`);
211+
});
205212
} catch (e) {
206213
await FileUtils.recursiveRemoveDirectoryIfExists(profile.getProfilePath());
207214
throw e;

0 commit comments

Comments
 (0)