File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -411,6 +411,9 @@ const initFileIpc = (): void => {
411411 const songDownload = await download ( win , url , {
412412 directory : downloadPath ,
413413 filename : `${ fileName } .${ fileType } ` ,
414+ onProgress : ( progress ) => {
415+ win . webContents . send ( "download-progress" , progress ) ;
416+ } ,
414417 } ) ;
415418 if ( ! downloadMeta || ! songData ?. cover ) return true ;
416419 // 下载封面
Original file line number Diff line number Diff line change @@ -419,6 +419,19 @@ const executeBatchDownload = async (songs: SongType[]) => {
419419
420420 const loadingMsg = window .$message .loading (` 正在准备批量下载... 0/${total } ` , { duration: 0 });
421421
422+ // 监听下载进度
423+ const onProgress = (_event : any , progress : { percent: number ; transferredBytes: number ; totalBytes: number }) => {
424+ const { percent, transferredBytes, totalBytes } = progress ;
425+ const percentStr = (percent * 100 ).toFixed (0 ) + " %" ;
426+ const transferredStr = (transferredBytes / 1024 / 1024 ).toFixed (2 ) + " MB" ;
427+ const totalStr = (totalBytes / 1024 / 1024 ).toFixed (2 ) + " MB" ;
428+ loadingMsg .content = ` 正在批量下载... ${processed + 1 }/${total } (成功 ${successCount }) - ${percentStr } ${transferredStr }/${totalStr } ` ;
429+ };
430+
431+ if (isElectron ) {
432+ window .electron .ipcRenderer .on (" download-progress" , onProgress );
433+ }
434+
422435 try {
423436 for (const song of songs ) {
424437 try {
@@ -465,7 +478,11 @@ const executeBatchDownload = async (songs: SongType[]) => {
465478 } catch (error ) {
466479 console .error (" Batch download error:" , error );
467480 window .$message .error (" 批量下载过程中出现错误" );
481+ window .$message .error (" 批量下载过程中出现错误" );
468482 } finally {
483+ if (isElectron ) {
484+ window .electron .ipcRenderer .removeListener (" download-progress" , onProgress );
485+ }
469486 loadingMsg .destroy ();
470487 }
471488};
You can’t perform that action at this time.
0 commit comments