I would like to show the progress of two different files when downloading.
But when I start one download and then another one the progress messes up.
In my background.ts
I have the following code to start downloads, send the progress and send an information about finishing it.
const downloadItems = [];
ipcMain.on(
'download-update',
async (event, { url, downloadPath, updateIdentificator }) => {
if (win) {
await download(win, url, {
directory: downloadPath,
onStarted: item => {
downloadItems[updateIdentificator] = item;
win.webContents.send('download-update-started', {
fileName: item.getFilename(),
updateIdentificator,
});
},
onProgress: currentProgress => {
win.webContents.send('download-update-progress', {
currentProgress,
updateIdentificator,
});
},
});
win.webContents.send('download-update-finished', {
updateIdentificator,
});
}
},
);
I have the same updateIdentificator
also in my view because I have one component used several times (with the same listener).
ipcMain.on(
'cancel-update',
(event, { updateIdentificator }) => {
if (downloadItems[updateIdentificator]) {
downloadItems[updateIdentificator].cancel();
}
if (win) {
win.webContents.send('update-canceled', {
updateIdentificator,
});
}
},
);
In my application I am listening to the events. When I start the first one (small) the progres works fine. As soon as I start the second one (bigger) the progress of the first one changes as well (probably because it shows the full progress for the application download?).
But my progressbar for the first download is broken now. After the first one finishes I get successfully the finished event for it.
Please let me know if there is anything unclear or missing.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too