mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
playlist download progressBar using chokidar
This commit is contained in:
@ -5,6 +5,7 @@ const { URL } = require("url");
|
||||
const { dialog, ipcMain } = require("electron");
|
||||
const is = require("electron-is");
|
||||
const ytpl = require("ytpl");
|
||||
const chokidar = require('chokidar');
|
||||
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const getSongInfo = require("../../providers/song-info");
|
||||
@ -51,14 +52,6 @@ module.exports = (win, options, refreshMenu) => {
|
||||
}
|
||||
mkdirSync(playlistFolder, { recursive: true });
|
||||
|
||||
ipcMain.on("downloader-feedback", (_, feedback) => {
|
||||
downloadLabel = feedback;
|
||||
refreshMenu();
|
||||
});
|
||||
|
||||
downloadLabel = `Downloading "${playlistTitle}"`;
|
||||
refreshMenu();
|
||||
|
||||
dialog.showMessageBox({
|
||||
type: "info",
|
||||
buttons: ["OK"],
|
||||
@ -73,6 +66,23 @@ module.exports = (win, options, refreshMenu) => {
|
||||
);
|
||||
}
|
||||
|
||||
const steps = 1 / playlist.items.length;
|
||||
let progress = 0;
|
||||
|
||||
win.setProgressBar(2); // starts with indefinite bar
|
||||
|
||||
let dirWatcher = chokidar.watch(playlistFolder);
|
||||
dirWatcher.on('add', () => {
|
||||
console.log(`progress:${progress} + steps:${steps} = newProgress:${progress+steps}`)
|
||||
progress += steps;
|
||||
if (progress >= 0.999) {
|
||||
win.setProgressBar(-1); // close progress bar
|
||||
dirWatcher.close().then(() => dirWatcher = null);
|
||||
} else {
|
||||
win.setProgressBar(progress);
|
||||
}
|
||||
});
|
||||
|
||||
playlist.items.forEach((song) => {
|
||||
win.webContents.send(
|
||||
"downloader-download-playlist",
|
||||
|
||||
Reference in New Issue
Block a user