1
1
<template >
2
2
<div >
3
- <div id =' downloadProgressModal' :class =" ['modal', {'is-active':downloadingMod}]" v-if =" downloadObject !== null " >
3
+ <div id =' downloadProgressModal' :class =" ['modal', {'is-active':downloadingMod}]" v-if =" downloadingMod " >
4
4
<div class =" modal-background" @click =" downloadingMod = false;" ></div >
5
5
<div class =' modal-content' >
6
6
<div class =' notification is-info' >
7
- <h3 class =' title' >Downloading {{downloadObject.modName }}</h3 >
8
- <p >{{Math.floor(downloadObject.progress )}}% complete</p >
7
+ <h3 class =' title' >Downloading {{activeDownloadModName }}</h3 >
8
+ <p >{{Math.floor(downloadProgress )}}% complete</p >
9
9
<Progress
10
10
:max =' 100'
11
- :value =' downloadObject.progress '
11
+ :value =' downloadProgress '
12
12
:className =" ['is-dark']"
13
13
/>
14
14
</div >
91
91
<script lang="ts">
92
92
93
93
import { Component , Vue , Watch } from ' vue-property-decorator' ;
94
+ import { mapGetters } from ' vuex' ;
94
95
import ThunderstoreMod from ' ../../model/ThunderstoreMod' ;
95
96
import ManifestV2 from ' ../../model/ManifestV2' ;
96
97
import ThunderstoreVersion from ' ../../model/ThunderstoreVersion' ;
@@ -123,6 +124,11 @@ let assignId = 0;
123
124
components: {
124
125
ModalCard ,
125
126
Progress
127
+ },
128
+ computed: {
129
+ ... mapGetters ({
130
+ activeDownloadProgress: ' modDownload/activeDownloadProgress'
131
+ })
126
132
}
127
133
})
128
134
export default class DownloadModModal extends Vue {
@@ -133,6 +139,8 @@ let assignId = 0;
133
139
downloadingMod: boolean = false ;
134
140
selectedVersion: string | null = null ;
135
141
currentVersion: string | null = null ;
142
+ downloadProgress: number | null = 0 ;
143
+ activeDownloadModName: string | null = null ;
136
144
137
145
static allVersions: [number , DownloadProgress ][] = [];
138
146
@@ -220,6 +228,11 @@ let assignId = 0;
220
228
return this .$store .state .modals .isDownloadModModalOpen ;
221
229
}
222
230
231
+ @Watch (' activeDownloadProgress' )
232
+ async updateProgress() {
233
+ this .downloadProgress = this .$store .getters [' modDownload/activeDownloadProgress' ];
234
+ }
235
+
223
236
@Watch (' $store.state.modals.downloadModModalMod' )
224
237
async getModVersions() {
225
238
this .currentVersion = null ;
@@ -326,47 +339,17 @@ let assignId = 0;
326
339
}, this .downloadCompletedCallback );
327
340
}
328
341
329
- downloadHandler(tsMod : ThunderstoreMod , tsVersion : ThunderstoreVersion ) {
342
+ async downloadHandler(tsMod : ThunderstoreMod , tsVersion : ThunderstoreVersion ) {
330
343
this .closeModal ();
331
- const currentAssignId = assignId ++ ;
332
- const progressObject = {
333
- progress: 0 ,
334
- initialMods: [` ${tsMod .getName ()} (${tsVersion .getVersionNumber ().toString ()}) ` ],
335
- modName: ' ' ,
336
- assignId: currentAssignId ,
337
- failed: false ,
338
- };
339
- this .downloadObject = progressObject ;
340
- DownloadModModal .allVersions .push ([currentAssignId , this .downloadObject ]);
344
+ this .activeDownloadModName = tsMod .getName ();
341
345
this .downloadingMod = true ;
342
- setTimeout (() => {
343
- ThunderstoreDownloaderProvider .instance .download (this .profile .asImmutableProfile (), tsMod , tsVersion , this .ignoreCache , (progress : number , modName : string , status : number , err : R2Error | null ) => {
344
- const assignIndex = DownloadModModal .allVersions .findIndex (([number , val ]) => number === currentAssignId );
345
- if (status === StatusEnum .FAILURE ) {
346
- if (err !== null ) {
347
- this .downloadingMod = false ;
348
- const existing = DownloadModModal .allVersions [assignIndex ]
349
- existing [1 ].failed = true ;
350
- this .$set (DownloadModModal .allVersions , assignIndex , [currentAssignId , existing [1 ]]);
351
- DownloadModModal .addSolutionsToError (err );
352
- this .$store .commit (' error/handleError' , err );
353
- return ;
354
- }
355
- } else if (status === StatusEnum .PENDING ) {
356
- const obj = {
357
- progress: progress ,
358
- initialMods: [` ${tsMod .getName ()} (${tsVersion .getVersionNumber ().toString ()}) ` ],
359
- modName: modName ,
360
- assignId: currentAssignId ,
361
- failed: false ,
362
- }
363
- if (this .downloadObject ! .assignId === currentAssignId ) {
364
- this .downloadObject = Object .assign ({}, obj );
365
- }
366
- this .$set (DownloadModModal .allVersions , assignIndex , [currentAssignId , obj ]);
367
- }
368
- }, this .downloadCompletedCallback );
369
- }, 1 );
346
+
347
+ await this .$store .dispatch (
348
+ ' modDownload/downloadAndInstallMod' ,
349
+ { profile: this .profile .asImmutableProfile (), mod: tsMod , version: tsVersion }
350
+ ).catch ((reason ) => this .$store .commit (' error/handleError' , R2Error .fromThrownValue (reason )));
351
+ this .activeDownloadModName = null ;
352
+ this .downloadingMod = false ;
370
353
}
371
354
372
355
async downloadCompletedCallback(downloadedMods : ThunderstoreCombo []) {
0 commit comments