Add support to disable auto updates

pull/112/head
Andrew 3 years ago
parent 742d9c2c0f
commit d94a711d9b

@ -162,10 +162,10 @@
<span id="trayTxt">Close to system tray</span>
<input type="checkbox" id="closeToTray">
</div>
<br>
<div class="prefBox">
<span id="autoUpdateTxt">Disable auto updates</span>
<input type="checkbox" id="closeToTray">
<input type="checkbox" id="autoUpdateDisabled">
</div>
</body>

@ -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();
}
});
}
}
});
);
}
});

@ -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");

@ -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();

@ -95,5 +95,6 @@
"Good":"Good",
"Bad":"Bad",
"Worst":"Worst",
"Select Quality":"Select Quality"
"Select Quality":"Select Quality",
"Disable auto updates":"Disable auto updates"
}

Loading…
Cancel
Save