Download progress in taskbar

pull/191/head
Andrew 2 years ago
parent 14f45830f2
commit 25fb910c56

@ -12,27 +12,31 @@ const {autoUpdater} = require("electron-updater");
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
const fs = require("fs");
const path = require("path");
autoUpdater.autoDownload = false;
/**@type {BrowserWindow} */
let win = null;
let secondaryWindow = null;
let tray = null;
let isQuiting = false;
let indexIsOpen = true;
let trayEnabled = false;
const configFile = path.join(app.getPath("userData"), "config.json");
function createWindow() {
const bounds = JSON.parse((getItem("bounds", configFile) || "{}"));
console.log("bounds:", bounds)
win = new BrowserWindow({
autoHideMenuBar: true,
show: false,
icon: __dirname + "/assets/images/icon.png",
// @ts-ignore
spellcheck: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
spellcheck: false,
},
});
win.setBounds(bounds)
win.on("close", (event) => {
if (!isQuiting && trayEnabled) {
event.preventDefault();
@ -41,11 +45,14 @@ function createWindow() {
}
return false;
});
win.on("resize", (event) => {
setItem("bounds", JSON.stringify(win.getBounds()), configFile);
});
win.loadFile("html/index.html");
win.maximize();
// win.setMenu(null)
win.show();
// win.webContents.openDevTools();
autoUpdater.checkForUpdates();
}
let loadedLanguage;
@ -56,7 +63,6 @@ if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
win.show();
}
@ -311,6 +317,12 @@ ipcMain.on("autoUpdate", (event, status) => {
}
});
ipcMain.on("progress", (_event, percentage) => {
if (win) {
win.setProgressBar(percentage)
}
})
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
/**
* @type {Electron.MessageBoxOptions}
@ -338,3 +350,39 @@ function i18n(phrase) {
}
return translation;
}
/**
* @param {string} itemName
* @param {string} itemContent
* @param {string} configPath
*/
function setItem(itemName, itemContent, configPath) {
let config = {};
if (fs.existsSync(configPath)) {
const fileContent = fs.readFileSync(configPath).toString();
config = JSON.parse(fileContent);
config[itemName] = itemContent;
} else {
config[itemName] = itemContent;
}
fs.writeFileSync(configPath, JSON.stringify(config));
}
/**
* @param {string} item
* @param {string} configPath
* @returns {string}
*/
function getItem(item, configPath) {
if (fs.existsSync(configPath)) {
try {
const configData = JSON.parse(fs.readFileSync(configPath, "utf8"));
return configData[item] || "";
} catch (err) {
return "";
}
} else {
return "";
}
}

@ -4,7 +4,7 @@
"yt-dlp-wrap-plus": "^2.3.18"
},
"name": "ytdownloader",
"version": "3.16.1",
"version": "3.16.2",
"main": "main.js",
"scripts": {
"start": "electron .",

@ -466,15 +466,16 @@ async function getInfo(url) {
1000000
).toFixed(2);
} else {
if (format.tbr) {
size = (
(format.tbr * 128 * duration) /
1000000
).toFixed(2);
} else {
// if (format.tbr) {
// size = (
// (format.tbr * 50 * duration) /
// 1000000
// ).toFixed(2);
// } else {
// }
size = i18n.__("Unknown size");
}
}
// For videos
@ -526,7 +527,9 @@ async function getInfo(url) {
format.format_id ||
"Unknown quality";
const spaceAfterQuality = "&#160".repeat(
8 - quality.length
quality.length > 8 && 8 - quality.length > 0
? 8 - quality.length
: quality.length + 2
);
// Extension
@ -1121,16 +1124,21 @@ function download(
if (progress.percent == 100) {
getId(randomId + "prog").textContent =
i18n.__("Processing") + "...";
ipcRenderer.send("progress", 0)
} else {
getId(randomId + "speed").textContent = `${i18n.__("Speed")}: ${
progress.currentSpeed || 0
}`;
}`; ipcRenderer.send("progress", progress.percent)
getId(
randomId + "prog"
).innerHTML = `<progress class="progressBar" min=0 max=100 value=${progress.percent}>`;
ipcRenderer.send("progress", progress.percent / 100)
}
})
.once("ytDlpEvent", (eventType, eventData) => {
.once("ytDlpEvent", (_eventType, _eventData) => {
getId(randomId + "prog").textContent = i18n.__("Downloading...");
})
.once("close", (code) => {

Loading…
Cancel
Save