Skip to content

Commit 59858ab

Browse files
authored
Merge pull request #603 from imsyy/dev-download
🎈 perf: 更详细的下载信息
2 parents 18c53b0 + 1a1130a commit 59858ab

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

electron/main/ipc/ipc-file.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
// 下载封面

src/components/Modal/BatchList.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)