@@ -262,8 +262,6 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
262
262
return { err, statusCode, statusMessage, responseBody } ;
263
263
} ) ;
264
264
265
-
266
-
267
265
ipcMain . handle ( 'showMessageBox' , async ( _event , options ) => dialog . showMessageBox ( mainWindow , options ) ) ;
268
266
269
267
ipcMain . handle ( 'showOpenDialog' , async ( _event , options ) => dialog . showOpenDialog ( options ) ) ;
@@ -322,53 +320,57 @@ if (ensureSingleInstance() && ensureCorrectEnvironment()) {
322
320
return responseObj ;
323
321
} ) ;
324
322
323
+ ipcMain . handle (
324
+ 'startMultipleDownload' ,
325
+ async ( _event : any , options : { folder : string ; tasks : { url : string ; filename : string } [ ] } ) => {
326
+ /* eslint no-await-in-loop: off -- we want to handle each file separately! */
327
+ let totalDownloadedSize = 0 ;
328
+ let successFileCount = 0 ;
329
+ let errorFileCount = 0 ;
330
+
331
+ const { folder, tasks } = options ;
332
+
333
+ for ( let i = 0 ; i < tasks . length ; i ++ ) {
334
+ const { url : downloadUrl , filename } = tasks [ i ] ;
335
+
336
+ try {
337
+ const sanitizedFilename = sanitizeFilename ( filename ) ;
338
+ if ( sanitizedFilename !== filename ) {
339
+ throw new Error (
340
+ `Filename ${ filename } contains invalid characters. Filename sanitized to ${ sanitizedFilename } ` ,
341
+ ) ;
342
+ }
343
+
344
+ const filePath = path . join ( folder , sanitizedFilename ) ;
345
+
346
+ await downloadFile ( downloadUrl , filePath , {
347
+ onProgress : ( progress ) => {
348
+ mainWindow ?. webContents . send ( 'multipleDownloadProgress' , {
349
+ progress,
350
+ url : downloadUrl ,
351
+ index : i ,
352
+ total : tasks . length ,
353
+ } ) ;
354
+ } ,
355
+ } ) ;
325
356
326
- ipcMain . handle ( 'startMultipleDownload' , async ( _event : any , options : { folder : string , tasks : { url : string ; filename : string } [ ] } ) => {
327
- /* eslint no-await-in-loop: off -- we want to handle each file separately! */
328
- let totalDownloadedSize = 0 ;
329
- let successFileCount = 0 ;
330
- let errorFileCount = 0 ;
331
-
332
- const { folder, tasks } = options ;
333
-
334
- for ( let i = 0 ; i < tasks . length ; i ++ ) {
335
- const { url : downloadUrl , filename } = tasks [ i ] ;
336
-
337
- try {
338
- const sanitizedFilename = sanitizeFilename ( filename ) ;
339
- if ( sanitizedFilename !== filename ) {
340
- throw new Error ( `Filename ${ filename } contains invalid characters. Filename sanitized to ${ sanitizedFilename } ` ) ;
341
- }
342
-
343
- const filePath = path . join ( folder , sanitizedFilename ) ;
344
-
345
- await downloadFile ( downloadUrl , filePath , {
346
- onProgress : ( progress ) => {
347
- mainWindow ?. webContents . send ( 'multipleDownloadProgress' , {
348
- progress,
349
- url : downloadUrl ,
350
- index : i ,
351
- total : tasks . length ,
352
- } ) ;
353
- } ,
354
- } ) ;
355
-
356
- const fileStats = await fs . promises . stat ( filePath ) ;
357
+ const fileStats = await fs . promises . stat ( filePath ) ;
357
358
358
- totalDownloadedSize += fileStats . size ;
359
- successFileCount ++ ;
360
- } catch ( e : any ) {
361
- if ( e . message === 'download aborted' && abortDownloadingFiles ) {
362
- break ;
359
+ totalDownloadedSize += fileStats . size ;
360
+ successFileCount ++ ;
361
+ } catch ( e : any ) {
362
+ if ( e . message === 'download aborted' && abortDownloadingFiles ) {
363
+ break ;
364
+ }
365
+ mainWindow ?. webContents . send ( 'errorDownloadingUrl' , downloadUrl ) ;
366
+ errorFileCount ++ ;
363
367
}
364
- mainWindow ?. webContents . send ( 'errorDownloadingUrl' , downloadUrl ) ;
365
- errorFileCount ++ ;
366
368
}
367
- }
368
- abortDownloadingFiles = false ;
369
- mainWindow ?. webContents . send ( 'multipleDownloadDone' , { totalDownloadedSize , successFileCount , errorFileCount } ) ;
370
- return true ;
371
- } ) ;
369
+ abortDownloadingFiles = false ;
370
+ mainWindow ?. webContents . send ( 'multipleDownloadDone' , { totalDownloadedSize , successFileCount , errorFileCount } ) ;
371
+ return true ;
372
+ } ,
373
+ ) ;
372
374
373
375
ipcMain . handle ( 'abortDownloadingFiles' , async ( _event : any ) => {
374
376
abortDownloadingFiles = true ;
0 commit comments