1
1
<template >
2
2
<div >
3
3
<div id =' downloadProgressModal' :class =" ['modal', {'is-active':$store.state.download.isModProgressModalOpen}]" v-if =" $store.getters['download/currentDownload'] !== null" >
4
- <div class =" modal-background" @click =" $store.commit('download/ setIsModProgressModalOpen', false);" ></div >
4
+ <div class =" modal-background" @click =" setIsModProgressModalOpen( false);" ></div >
5
5
<div class =' modal-content' >
6
6
<div class =' notification is-info' >
7
7
<h3 class =' title' >Downloading {{$store.getters['download/currentDownload'].modName}}</h3 >
13
13
/>
14
14
</div >
15
15
</div >
16
- <button class =" modal-close is-large" aria-label =" close" @click =" $store.commit('download/ setIsModProgressModalOpen', false);" ></button >
16
+ <button class =" modal-close is-large" aria-label =" close" @click =" setIsModProgressModalOpen( false);" ></button >
17
17
</div >
18
18
<DownloadModVersionSelectModal @download-mod =" downloadHandler" />
19
19
<UpdateAllInstalledModsModal />
@@ -60,54 +60,65 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
60
60
store : Store <any >
61
61
): Promise <void > {
62
62
return new Promise (async (resolve , reject ) => {
63
- const tsMod = combo .getMod ();
64
- const tsVersion = combo .getVersion ();
65
63
66
64
const assignId = await store .dispatch (
67
65
' download/addDownload' ,
68
- [` ${tsMod . getName ()} (${tsVersion .getVersionNumber ().toString ()}) ` ]
66
+ [` ${combo . getMod (). getName ()} (${combo . getVersion () .getVersionNumber ().toString ()}) ` ]
69
67
);
70
68
71
- setTimeout (() => {
72
- ThunderstoreDownloaderProvider .instance .download (profile .asImmutableProfile (), tsMod , tsVersion , ignoreCache , (progress : number , modName : string , status : number , err : R2Error | null ) => {
73
- try {
74
- if (status === StatusEnum .FAILURE ) {
75
- store .commit (' download/updateDownload' , {assignId , failed: true });
76
- if (err !== null ) {
77
- DownloadMixin .addSolutionsToError (err );
78
- return reject (err );
79
- }
80
- } else if (status === StatusEnum .PENDING ) {
81
- store .commit (' download/updateDownload' , {assignId , progress , modName });
82
- }
83
- } catch (e ) {
84
- return reject (e );
85
- }
86
- }, async (downloadedMods : ThunderstoreCombo []) => {
87
- ProfileModList .requestLock (async () => {
88
- for (const combo of downloadedMods ) {
69
+ setTimeout (async () => {
70
+ let downloadedMods: ThunderstoreCombo [] = [];
71
+ try {
72
+ downloadedMods = await ThunderstoreDownloaderProvider .instance .download (
73
+ profile .asImmutableProfile (),
74
+ combo ,
75
+ ignoreCache ,
76
+ (progress : number , modName : string , status : number , err : R2Error | null ) => {
89
77
try {
90
- await DownloadModModal .installModAfterDownload ( profile , combo . getMod (), combo . getVersion () );
78
+ DownloadModModal .downloadProgressCallback ( store , assignId , progress , modName , status , err );
91
79
} catch (e ) {
92
- return reject (
93
- R2Error .fromThrownValue (e , ` Failed to install mod [${combo .getMod ().getFullName ()}] ` )
94
- );
80
+ reject (e );
95
81
}
96
82
}
97
- const modList = await ProfileModList .getModList (profile .asImmutableProfile ());
98
- if (! (modList instanceof R2Error )) {
99
- const err = await ConflictManagementProvider .instance .resolveConflicts (modList , profile .asImmutableProfile ());
100
- if (err instanceof R2Error ) {
101
- return reject (err );
102
- }
83
+ );
84
+ } catch (e ) {
85
+ return reject (e );
86
+ }
87
+ await ProfileModList .requestLock (async () => {
88
+ for (const combo of downloadedMods ) {
89
+ try {
90
+ await DownloadModModal .installModAfterDownload (profile , combo .getMod (), combo .getVersion ());
91
+ } catch (e ) {
92
+ return reject (
93
+ R2Error .fromThrownValue (e , ` Failed to install mod [${combo .getMod ().getFullName ()}] ` )
94
+ );
103
95
}
104
- return resolve ();
105
- });
96
+ }
97
+ const modList = await ProfileModList .getModList (profile .asImmutableProfile ());
98
+ if (! (modList instanceof R2Error )) {
99
+ const err = await ConflictManagementProvider .instance .resolveConflicts (modList , profile .asImmutableProfile ());
100
+ if (err instanceof R2Error ) {
101
+ return reject (err );
102
+ }
103
+ }
104
+ return resolve ();
106
105
});
107
106
}, 1 );
108
107
});
109
108
}
110
109
110
+ static downloadProgressCallback(store : Store <any >, assignId : number , progress : number , modName : string , status : number , err : R2Error | null ) {
111
+ if (status === StatusEnum .FAILURE ) {
112
+ store .commit (' download/updateDownload' , {assignId , failed: true });
113
+ if (err !== null ) {
114
+ DownloadMixin .addSolutionsToError (err );
115
+ throw err ;
116
+ }
117
+ } else if (status === StatusEnum .PENDING ) {
118
+ store .commit (' download/updateDownload' , {assignId , progress , modName });
119
+ }
120
+ }
121
+
111
122
async downloadHandler(tsMod : ThunderstoreMod , tsVersion : ThunderstoreVersion ) {
112
123
this .closeModal ();
113
124
@@ -116,30 +127,49 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
116
127
[` ${tsMod .getName ()} (${tsVersion .getVersionNumber ().toString ()}) ` ]
117
128
);
118
129
119
- this .$store .commit (' download/setIsModProgressModalOpen' , true );
120
- setTimeout (() => {
121
- ThunderstoreDownloaderProvider .instance .download (this .profile .asImmutableProfile (), tsMod , tsVersion , this .ignoreCache , (progress : number , modName : string , status : number , err : R2Error | null ) => {
122
- try {
123
- if (status === StatusEnum .FAILURE ) {
124
- this .$store .commit (' download/setIsModProgressModalOpen' , false );
125
- this .$store .commit (' download/updateDownload' , {assignId , failed: true });
126
- if (err !== null ) {
127
- DownloadMixin .addSolutionsToError (err );
128
- throw err ;
129
- }
130
- } else if (status === StatusEnum .PENDING ) {
131
- this .$store .commit (' download/updateDownload' , {assignId , progress , modName });
132
- }
133
- } catch (e ) {
134
- this .$store .commit (' error/handleError' , R2Error .fromThrownValue (e ));
135
- }
136
- }, async (downloadedMods ) => {
137
- await this .downloadCompletedCallback (downloadedMods );
138
- this .$store .commit (' download/setIsModProgressModalOpen' , false );
139
- });
130
+ this .setIsModProgressModalOpen (true );
131
+
132
+ const tsCombo = new ThunderstoreCombo ();
133
+ tsCombo .setMod (tsMod );
134
+ tsCombo .setVersion (tsVersion );
135
+
136
+ setTimeout (async () => {
137
+ let downloadedMods: ThunderstoreCombo [] = [];
138
+ try {
139
+ downloadedMods = await ThunderstoreDownloaderProvider .instance .download (
140
+ this .profile .asImmutableProfile (),
141
+ tsCombo ,
142
+ this .ignoreCache ,
143
+ (progress , modName , status , err ) => { this .downloadProgressCallback (assignId , progress , modName , status , err ); }
144
+ );
145
+ } catch (e ) {
146
+ this .setIsModProgressModalOpen (false );
147
+ this .$store .commit (' error/handleError' , R2Error .fromThrownValue (e ));
148
+ return ;
149
+ }
150
+ await this .downloadCompletedCallback (downloadedMods );
151
+ this .setIsModProgressModalOpen (false );
140
152
}, 1 );
153
+
141
154
}
142
155
156
+ downloadProgressCallback(assignId : number , progress : number , modName : string , status : number , err : R2Error | null ) {
157
+ try {
158
+ if (status === StatusEnum .FAILURE ) {
159
+ this .setIsModProgressModalOpen (false );
160
+ this .$store .commit (' download/updateDownload' , {assignId , failed: true });
161
+ if (err !== null ) {
162
+ DownloadMixin .addSolutionsToError (err );
163
+ throw err ;
164
+ }
165
+ } else if (status === StatusEnum .PENDING ) {
166
+ this .$store .commit (' download/updateDownload' , {assignId , progress , modName });
167
+ }
168
+ } catch (e ) {
169
+ this .$store .commit (' error/handleError' , R2Error .fromThrownValue (e ));
170
+ }
171
+ };
172
+
143
173
static async installModAfterDownload(profile : Profile , mod : ThunderstoreMod , version : ThunderstoreVersion ): Promise <R2Error | void > {
144
174
return new Promise (async (resolve , reject ) => {
145
175
const manifestMod: ManifestV2 = new ManifestV2 ().fromThunderstoreMod (mod , version );
0 commit comments