Fix update mechanism for macOS

pull/43/head
aandrew-me 3 years ago
parent 05fd54e5b1
commit 026c627da3

@ -1,9 +1,9 @@
const { app, BrowserWindow, dialog, ipcMain } = require("electron"); const { app, BrowserWindow, dialog, ipcMain, shell } = require("electron");
const { autoUpdater } = require("electron-updater"); const { autoUpdater } = require("electron-updater");
autoUpdater.autoDownload = false; autoUpdater.autoDownload = false;
let win, secondaryWindow; let win, secondaryWindow;
app.commandLine.appendSwitch("--enable-features", "Metal") app.commandLine.appendSwitch("--enable-features", "Metal");
function createWindow() { function createWindow() {
let isTransparent = false; let isTransparent = false;
@ -18,7 +18,7 @@ function createWindow() {
transparent: isTransparent, transparent: isTransparent,
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false contextIsolation: false,
}, },
}); });
@ -27,9 +27,7 @@ function createWindow() {
// win.setMenu(null) // win.setMenu(null)
win.show(); win.show();
// win.webContents.openDevTools(); // win.webContents.openDevTools();
if (process.platform !== "darwin"){ autoUpdater.checkForUpdates();
autoUpdater.checkForUpdates();
}
} }
app.whenReady().then(() => { app.whenReady().then(() => {
@ -51,16 +49,16 @@ app.whenReady().then(() => {
ipcMain.on("restart", () => { ipcMain.on("restart", () => {
app.relaunch(); app.relaunch();
app.exit(); app.exit();
}) });
ipcMain.on("get-version", () => { ipcMain.on("get-version", () => {
const version = app.getVersion(); const version = app.getVersion();
secondaryWindow.webContents.send("version", version); secondaryWindow.webContents.send("version", version);
}); });
ipcMain.on("load-win", (event, file)=>{ ipcMain.on("load-win", (event, file) => {
win.loadFile(file) win.loadFile(file);
}) });
ipcMain.on("load-page", (event, file) => { ipcMain.on("load-page", (event, file) => {
secondaryWindow = new BrowserWindow({ secondaryWindow = new BrowserWindow({
webPreferences: { webPreferences: {
@ -100,18 +98,38 @@ app.on("window-all-closed", () => {
// Auto updater events // Auto updater events
autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => { autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => {
const dialogOpts = { // For macOS
type: "info", if (process.platform === "darwin") {
buttons: ["Update", "No"], const dialogOpts = {
title: "Update Available", type: "info",
detail: process.platform === "win32" ? releaseNotes : releaseName, buttons: ["Download", "No"],
message: "A new version is available, do you want to update?", title: "Update Available",
}; detail: releaseName,
dialog.showMessageBox(dialogOpts).then((returnValue) =>{ message: "A new version is available, do you want to download it?",
if (returnValue.response === 0) { };
autoUpdater.downloadUpdate(); 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: ["Update", "No"],
title: "Update Available",
detail: process.platform === "win32" ? releaseNotes : releaseName,
message: "A new version is available, do you want to update?",
};
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
autoUpdater.downloadUpdate();
}
});
}
}); });
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => { autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {

Loading…
Cancel
Save