@@ -31,6 +31,16 @@ export interface InstallStateEvent {
31
31
state : InstallState ;
32
32
}
33
33
34
+ export interface Mirrors {
35
+ electronMirror : string ;
36
+ electronNightlyMirror : string ;
37
+ }
38
+
39
+ interface InstallerParams {
40
+ progressCallback : ( progress : ProgressObject ) => void ;
41
+ mirror : Mirrors ;
42
+ }
43
+
34
44
/**
35
45
* Manage downloading and installing Electron versions.
36
46
*
@@ -190,9 +200,16 @@ export class Installer extends EventEmitter {
190
200
if ( state === 'installed' ) return version ;
191
201
}
192
202
193
- private async download ( version : string ) : Promise < string > {
203
+ private async download (
204
+ version : string ,
205
+ opts ?: Partial < InstallerParams > ,
206
+ ) : Promise < string > {
194
207
let pctDone = 0 ;
195
208
const getProgressCallback = ( progress : ProgressObject ) => {
209
+ if ( opts ?. progressCallback ) {
210
+ // Call the user passed callback function
211
+ opts . progressCallback ( progress ) ;
212
+ }
196
213
const pct = Math . round ( progress . percent * 100 ) ;
197
214
if ( pctDone + 10 <= pct ) {
198
215
const emoji = pct >= 100 ? '🏁' : '⏳' ;
@@ -202,6 +219,10 @@ export class Installer extends EventEmitter {
202
219
}
203
220
} ;
204
221
const zipFile = await electronDownload ( version , {
222
+ mirrorOptions : {
223
+ mirror : opts ?. mirror ?. electronMirror ,
224
+ nightlyMirror : opts ?. mirror ?. electronNightlyMirror ,
225
+ } ,
205
226
downloadOptions : {
206
227
quiet : true ,
207
228
getProgressCallback,
@@ -210,7 +231,10 @@ export class Installer extends EventEmitter {
210
231
return zipFile ;
211
232
}
212
233
213
- private async ensureDownloadedImpl ( version : string ) : Promise < string > {
234
+ private async ensureDownloadedImpl (
235
+ version : string ,
236
+ opts ?: Partial < InstallerParams > ,
237
+ ) : Promise < string > {
214
238
const d = debug ( `fiddle-core:Installer:${ version } :ensureDownloadedImpl` ) ;
215
239
const { electronDownloads } = this . paths ;
216
240
const zipFile = path . join ( electronDownloads , getZipName ( version ) ) ;
@@ -219,7 +243,7 @@ export class Installer extends EventEmitter {
219
243
if ( state === 'missing' ) {
220
244
d ( `"${ zipFile } " does not exist; downloading now` ) ;
221
245
this . setState ( version , 'downloading' ) ;
222
- const tempFile = await this . download ( version ) ;
246
+ const tempFile = await this . download ( version , opts ) ;
223
247
await fs . ensureDir ( electronDownloads ) ;
224
248
await fs . move ( tempFile , zipFile ) ;
225
249
this . setState ( version , 'downloaded' ) ;
@@ -234,12 +258,15 @@ export class Installer extends EventEmitter {
234
258
/** map of version string to currently-running active Promise */
235
259
private downloading = new Map < string , Promise < string > > ( ) ;
236
260
237
- public async ensureDownloaded ( version : string ) : Promise < string > {
261
+ public async ensureDownloaded (
262
+ version : string ,
263
+ opts ?: Partial < InstallerParams > ,
264
+ ) : Promise < string > {
238
265
const { downloading : promises } = this ;
239
266
let promise = promises . get ( version ) ;
240
267
if ( promise ) return promise ;
241
268
242
- promise = this . ensureDownloadedImpl ( version ) . finally ( ( ) =>
269
+ promise = this . ensureDownloadedImpl ( version , opts ) . finally ( ( ) =>
243
270
promises . delete ( version ) ,
244
271
) ;
245
272
promises . set ( version , promise ) ;
@@ -249,7 +276,10 @@ export class Installer extends EventEmitter {
249
276
/** the currently-installing version, if any */
250
277
private installing : string | undefined ;
251
278
252
- public async install ( version : string ) : Promise < string > {
279
+ public async install (
280
+ version : string ,
281
+ opts ?: Partial < InstallerParams > ,
282
+ ) : Promise < string > {
253
283
const d = debug ( `fiddle-core:Installer:${ version } :install` ) ;
254
284
const { electronInstall } = this . paths ;
255
285
const electronExec = Installer . getExecPath ( electronInstall ) ;
@@ -262,7 +292,7 @@ export class Installer extends EventEmitter {
262
292
if ( installedVersion === version ) {
263
293
d ( `already installed` ) ;
264
294
} else {
265
- const zipFile = await this . ensureDownloaded ( version ) ;
295
+ const zipFile = await this . ensureDownloaded ( version , opts ) ;
266
296
this . setState ( version , 'installing' ) ;
267
297
d ( `installing from "${ zipFile } "` ) ;
268
298
await fs . emptyDir ( electronInstall ) ;
0 commit comments