set badge on downloader playlist

This commit is contained in:
Araxeus
2022-01-12 14:29:56 +02:00
parent ec4c2e92af
commit 17a24cbb04
2 changed files with 16 additions and 7 deletions

View File

@ -8,7 +8,7 @@ const chokidar = require('chokidar');
const { setOptions } = require("../../config/plugins"); const { setOptions } = require("../../config/plugins");
const { sendError } = require("./back"); const { sendError } = require("./back");
const { defaultMenuDownloadLabel, getFolder, presets } = require("./utils"); const { defaultMenuDownloadLabel, getFolder, presets, setBadge } = require("./utils");
let downloadLabel = defaultMenuDownloadLabel; let downloadLabel = defaultMenuDownloadLabel;
let playingPlaylistId = undefined; let playingPlaylistId = undefined;
@ -70,19 +70,21 @@ module.exports = (win, options) => {
); );
} }
const steps = 1 / playlist.items.length;
let progress = 0;
win.setProgressBar(2); // starts with indefinite bar win.setProgressBar(2); // starts with indefinite bar
let downloadCount = 0;
setBadge(playlist.items.length);
let dirWatcher = chokidar.watch(playlistFolder); let dirWatcher = chokidar.watch(playlistFolder);
dirWatcher.on('add', () => { dirWatcher.on('add', () => {
progress += steps; downloadCount += 1;
if (progress >= 0.9999) { if (downloadCount >= playlist.items.length) {
win.setProgressBar(-1); // close progress bar win.setProgressBar(-1); // close progress bar
setBadge(0); // close badge counter
dirWatcher.close().then(() => dirWatcher = null); dirWatcher.close().then(() => dirWatcher = null);
} else { } else {
win.setProgressBar(progress); win.setProgressBar(downloadCount / playlist.items.length);
setBadge(playlist.items.length - downloadCount);
} }
}); });

View File

@ -1,4 +1,5 @@
const electron = require("electron"); const electron = require("electron");
const is = require('electron-is');
module.exports.getFolder = customFolder => customFolder || electron.app.getPath("downloads"); module.exports.getFolder = customFolder => customFolder || electron.app.getPath("downloads");
module.exports.defaultMenuDownloadLabel = "Download playlist"; module.exports.defaultMenuDownloadLabel = "Download playlist";
@ -37,3 +38,9 @@ module.exports.presets = {
ffmpegArgs: ["-acodec", "libopus"], ffmpegArgs: ["-acodec", "libopus"],
}, },
}; };
module.exports.setBadge = num => {
if (is.linux() || is.macOS()) {
electron.app.badgeCount = num;
}
}