Added better auto-update handling. RPS-17
This commit is contained in:
116
electron/main.js
116
electron/main.js
@@ -19,6 +19,8 @@ const Nucleus = require("nucleus-nodejs");
|
||||
require("./ipc-main-handler");
|
||||
require("./analytics");
|
||||
|
||||
autoUpdater.autoDownload = false;
|
||||
|
||||
autoUpdater.logger = log;
|
||||
autoUpdater.logger.transports.file.level = "info";
|
||||
log.info("App starting...", app.getVersion());
|
||||
@@ -70,10 +72,7 @@ var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: `Check for Updates (currently ${app.getVersion()})`,
|
||||
click() {
|
||||
autoUpdater.checkForUpdatesAndNotify({
|
||||
title: "ImEX RPS Update Downloaded",
|
||||
body: "Restart ImEX RPS to install.",
|
||||
});
|
||||
checkForUpdates();
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -168,7 +167,6 @@ function createWindow() {
|
||||
}
|
||||
|
||||
mainWindow.maximize();
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
globalShortcut.register("CommandOrControl+Shift+I", () => {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
@@ -242,46 +240,22 @@ function createTray() {
|
||||
return appIcon;
|
||||
}
|
||||
|
||||
autoUpdater.on("checking-for-update", () => {
|
||||
log.log("Checking for update...");
|
||||
});
|
||||
autoUpdater.on("update-available", (ev, info) => {
|
||||
log.log("Update available.");
|
||||
});
|
||||
autoUpdater.on("update-not-available", (ev, info) => {
|
||||
log.log("Update not available.");
|
||||
});
|
||||
autoUpdater.on("error", (ev, err) => {
|
||||
log.log("Error in auto-updater.");
|
||||
});
|
||||
autoUpdater.on("download-progress", (ev, progressObj) => {
|
||||
log.log("Download progress...");
|
||||
});
|
||||
// autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
// console.log("Update downloaded; will install in 5 seconds");
|
||||
// autoUpdater.on("checking-for-update", () => {
|
||||
// log.log("Checking for update...");
|
||||
// });
|
||||
autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
Nucleus.track("UPDATE_DOWNLOADED", info);
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
dialog.showMessageBox(
|
||||
{
|
||||
type: "info",
|
||||
title: "Found Updates",
|
||||
message: "Found updates, do you want update now?",
|
||||
buttons: ["Sure", "No"],
|
||||
},
|
||||
(buttonIndex) => {
|
||||
if (buttonIndex === 0) {
|
||||
const isSilent = true;
|
||||
const isForceRunAfter = true;
|
||||
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
} else {
|
||||
logger.warn("Error");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
// autoUpdater.on("update-available", (ev, info) => {
|
||||
// log.log("Update available.");
|
||||
// });
|
||||
// autoUpdater.on("update-not-available", (ev, info) => {
|
||||
// log.log("Update not available.");
|
||||
// });
|
||||
// autoUpdater.on("error", (ev, err) => {
|
||||
// log.log("Error in auto-updater.");
|
||||
// });
|
||||
|
||||
// // autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
// // console.log("Update downloaded; will install in 5 seconds");
|
||||
// // });
|
||||
|
||||
function openNoticeWindow() {
|
||||
if (noticeWindow) {
|
||||
@@ -301,3 +275,57 @@ function openNoticeWindow() {
|
||||
noticeWindow = null;
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.on(ipcTypes.app.toMain.checkForUpdates, (event, args) => {
|
||||
checkForUpdates();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.app.toMain.downloadUpdates, (event, args) => {
|
||||
autoUpdater.downloadUpdate();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.app.toMain.installUpdates, (event, args) => {
|
||||
const isSilent = true;
|
||||
const isForceRunAfter = true;
|
||||
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
});
|
||||
|
||||
autoUpdater.on("download-progress", (ev) => {
|
||||
mainWindow.webContents.send(ipcTypes.app.toRenderer.downloadProgress, ev);
|
||||
});
|
||||
|
||||
autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
Nucleus.track("UPDATE_DOWNLOADED", info);
|
||||
// if (process.env.NODE_ENV === "production") {
|
||||
|
||||
dialog.showMessageBox(
|
||||
{
|
||||
type: "info",
|
||||
title: "ImeX RPS Update Manager",
|
||||
message: `ImEX RPS is ready to update to Version ${ev.version}. It is highly recommended that you update immediately. Would you like to update now? RPS will automatically restart.`,
|
||||
buttons: ["Yes", "No"],
|
||||
},
|
||||
(buttonIndex) => {
|
||||
if (buttonIndex === 0) {
|
||||
const isSilent = true;
|
||||
const isForceRunAfter = true;
|
||||
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
|
||||
} else {
|
||||
logger.error("Error");
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
async function checkForUpdates() {
|
||||
try {
|
||||
log.info("Checking for updates.");
|
||||
const result = await autoUpdater.checkForUpdates();
|
||||
const { updateInfo } = result;
|
||||
mainWindow.webContents.send(
|
||||
ipcTypes.app.toRenderer.updateAvailable,
|
||||
updateInfo
|
||||
);
|
||||
} catch (error) {
|
||||
log.error("Error while checking for update", error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user