From 40fbf3441a52ed7b8c067077ac7669985513ef49 Mon Sep 17 00:00:00 2001 From: TC Date: Sun, 16 Jan 2022 17:29:21 +0100 Subject: [PATCH] Backport missing changes for playlist badge --- plugins/downloader/menu.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index a1913047..2f2df421 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -121,19 +121,21 @@ async function downloadPlaylist(givenUrl, win, options) { ); } - const steps = 1 / playlist.items.length; - let progress = 0; - win.setProgressBar(2); // starts with indefinite bar + let downloadCount = 0; + setBadge(playlist.items.length); + let dirWatcher = chokidar.watch(playlistFolder); dirWatcher.on('add', () => { - progress += steps; - if (progress >= 0.9999) { + downloadCount += 1; + if (downloadCount >= playlist.items.length) { win.setProgressBar(-1); // close progress bar - dirWatcher.close().then(() => dirWatcher = null); + setBadge(0); // close badge counter + dirWatcher.close().then(() => (dirWatcher = null)); } else { - win.setProgressBar(progress); + win.setProgressBar(downloadCount / playlist.items.length); + setBadge(playlist.items.length - downloadCount); } });