diff --git a/main.js b/main.js index aa05580..c177ead 100644 --- a/main.js +++ b/main.js @@ -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 ""; + } +} diff --git a/package.json b/package.json index 06d164a..57c75c6 100644 --- a/package.json +++ b/package.json @@ -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 .", diff --git a/src/renderer.js b/src/renderer.js index 195a24e..05bd4f1 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -466,14 +466,15 @@ async function getInfo(url) { 1000000 ).toFixed(2); } else { - if (format.tbr) { - size = ( - (format.tbr * 128 * duration) / - 1000000 - ).toFixed(2); - } else { - size = i18n.__("Unknown size"); - } + // 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 = " ".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 = ``; + + ipcRenderer.send("progress", progress.percent / 100) } }) - .once("ytDlpEvent", (eventType, eventData) => { + .once("ytDlpEvent", (_eventType, _eventData) => { getId(randomId + "prog").textContent = i18n.__("Downloading..."); }) .once("close", (code) => {