diff --git a/html/preferences.html b/html/preferences.html index c4e7cde..de756eb 100644 --- a/html/preferences.html +++ b/html/preferences.html @@ -162,10 +162,10 @@ Close to system tray - +
Disable auto updates - +
diff --git a/main.js b/main.js index 60256d6..6e0d38f 100644 --- a/main.js +++ b/main.js @@ -9,7 +9,7 @@ const { clipboard, } = require("electron"); const { autoUpdater } = require("electron-updater"); -process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true +process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; const fs = require("fs"); const path = require("path"); @@ -157,10 +157,10 @@ app.whenReady().then(() => { tray = new Tray(icon); tray.setToolTip("ytDownloader"); tray.setContextMenu(contextMenu); - tray.on("click", ()=>{ + tray.on("click", () => { win.show(); if (app.dock) app.dock.show(); - }) + }); } else if (!enabled) { trayEnabled = false; } @@ -240,41 +240,59 @@ ipcMain.on("select-config", () => { } }); -// Auto updater events -autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => { - // For macOS - if (process.platform === "darwin") { - const dialogOpts = { - type: "info", - buttons: [i18n("Download"), i18n("No")], - title: "Update Available", - detail: releaseName, - message: i18n( - "A new version is available, do you want to download it?" - ), - }; - dialog.showMessageBox(dialogOpts).then((returnValue) => { - if (returnValue.response === 0) { - shell.openExternal( - "https://github.com/aandrew-me/ytDownloader/releases/latest/download/YTDownloader_Mac.zip" - ); - } - }); - } - // For Windows and Linux - else { - const dialogOpts = { - type: "info", - buttons: [i18n("Update"), i18n("No")], - title: "Update Available", - detail: process.platform === "win32" ? releaseNotes : releaseName, - message: i18n("A new version is available, do you want to update?"), - }; - dialog.showMessageBox(dialogOpts).then((returnValue) => { - if (returnValue.response === 0) { - autoUpdater.downloadUpdate(); +// Auto update +let autoUpdate = false; + +ipcMain.on("autoUpdate", (event, status) => { + autoUpdate = status; + console.log("Auto update:", status); + + if (autoUpdate === true) { + // Auto updater events + autoUpdater.on( + "update-available", + (_event, releaseNotes, releaseName) => { + // For macOS + if (process.platform === "darwin") { + const dialogOpts = { + type: "info", + buttons: [i18n("Download"), i18n("No")], + title: "Update Available", + detail: releaseName, + message: i18n( + "A new version is available, do you want to download it?" + ), + }; + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) { + shell.openExternal( + "https://github.com/aandrew-me/ytDownloader/releases/latest/download/YTDownloader_Mac.zip" + ); + } + }); + } + // For Windows and Linux + else { + const dialogOpts = { + type: "info", + buttons: [i18n("Update"), i18n("No")], + title: "Update Available", + detail: + process.platform === "win32" + ? releaseNotes + : releaseName, + message: i18n( + "A new version is available, do you want to update?" + ), + }; + dialog.showMessageBox(dialogOpts).then((returnValue) => { + if (returnValue.response === 0) { + autoUpdater.downloadUpdate(); + } + }); + } } - }); + ); } }); diff --git a/src/preferences.js b/src/preferences.js index d744d4b..86b8531 100644 --- a/src/preferences.js +++ b/src/preferences.js @@ -207,5 +207,20 @@ if(trayEnabled == "true"){ ipcRenderer.send("useTray", true) } +// Auto updates +const autoUpdateDisabled = getId("autoUpdateDisabled"); +autoUpdateDisabled.addEventListener("change", (event) => { + if (autoUpdateDisabled.checked) { + localStorage.setItem("autoUpdate", "false"); + } else { + localStorage.setItem("autoUpdate", "true"); + + } +}); +const autoUpdate = localStorage.getItem("autoUpdate") +if (autoUpdate == "false"){ + autoUpdateDisabled.checked = true; +} + // Translation file require("../src/translate_preferences"); diff --git a/src/renderer.js b/src/renderer.js index 833c09b..4f95534 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -59,6 +59,16 @@ function checkMaxDownloads() { } checkMaxDownloads(); +// Check for auto updates +let autoUpdate = true; +const autoUpdateStatus = localStorage.getItem("autoUpdate") +if (autoUpdateStatus){ + if (autoUpdateStatus == "false"){ + autoUpdate = false + } +} +ipcRenderer.send("autoUpdate", autoUpdate); + let currentDownloads = 0; let controllers = new Object(); diff --git a/translations/en.json b/translations/en.json index 53d82e3..b380cba 100644 --- a/translations/en.json +++ b/translations/en.json @@ -95,5 +95,6 @@ "Good":"Good", "Bad":"Bad", "Worst":"Worst", - "Select Quality":"Select Quality" + "Select Quality":"Select Quality", + "Disable auto updates":"Disable auto updates" }