Updated package and distributor to work with S3. Added menu update.
This commit is contained in:
106
electron/main.js
106
electron/main.js
@@ -1,10 +1,20 @@
|
||||
const path = require("path");
|
||||
const { app, BrowserWindow, Tray, Menu, ipcMain } = require("electron");
|
||||
const {
|
||||
app,
|
||||
BrowserWindow,
|
||||
Tray,
|
||||
Menu,
|
||||
ipcMain,
|
||||
dialog,
|
||||
shell,
|
||||
globalShortcut,
|
||||
} = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
const { default: ipcTypes } = require("../src/ipc.types");
|
||||
const { store } = require("./electron-store");
|
||||
const { autoUpdater } = require("electron-updater");
|
||||
const log = require("electron-log");
|
||||
const { default: logger } = require("redux-logger");
|
||||
require("./ipc-main-handler");
|
||||
|
||||
autoUpdater.logger = log;
|
||||
@@ -13,18 +23,69 @@ log.info("App starting...");
|
||||
|
||||
// Conditionally include the dev tools installer to load React Dev Tools
|
||||
let installExtension, REACT_DEVELOPER_TOOLS;
|
||||
if (isDev) {
|
||||
const devTools = require("electron-devtools-installer");
|
||||
installExtension = devTools.default;
|
||||
REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
|
||||
}
|
||||
// if (isDev) {
|
||||
// const devTools = require("electron-devtools-installer");
|
||||
// installExtension = devTools.default;
|
||||
// REACT_DEVELOPER_TOOLS = devTools.REACT_DEVELOPER_TOOLS;
|
||||
// }
|
||||
|
||||
var menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: "File",
|
||||
submenu: [
|
||||
{
|
||||
label: "Relaunch",
|
||||
click() {
|
||||
app.exit();
|
||||
app.relaunch();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Clear Settings",
|
||||
click() {
|
||||
store.reset("filePaths");
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Exit",
|
||||
click() {
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
],
|
||||
// Other code removed for brevity
|
||||
},
|
||||
{
|
||||
label: "Help",
|
||||
submenu: [
|
||||
{
|
||||
label: "Rescue",
|
||||
click() {
|
||||
shell.openExternal("http://imexrescue.com");
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Check for Updates",
|
||||
click() {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Open Log File",
|
||||
click() {
|
||||
shell.openPath(store.path);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
let mainWindow;
|
||||
let tray = null;
|
||||
function createWindow() {
|
||||
makeSingleInstance();
|
||||
// Create the browser window.
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
@@ -33,7 +94,7 @@ function createWindow() {
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
enableRemoteModule: false,
|
||||
webSecurity: false,
|
||||
webSecurity: true,
|
||||
worldSafeExecuteJavaScript: true,
|
||||
contextIsolation: true,
|
||||
preload: path.join(__dirname, "preload.js"), // use a preload script
|
||||
@@ -73,6 +134,10 @@ function createWindow() {
|
||||
|
||||
mainWindow.maximize();
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
globalShortcut.register("CommandOrControl+Shift+I", () => {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
});
|
||||
}
|
||||
|
||||
exports.mainWindow = mainWindow;
|
||||
@@ -175,10 +240,23 @@ autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
console.log("Update downloaded; will install in 5 seconds");
|
||||
});
|
||||
autoUpdater.on("update-downloaded", (ev, info) => {
|
||||
// Wait 5 seconds, then quit and install
|
||||
// In your application, you don't need to wait 5 seconds.
|
||||
// You could call autoUpdater.quitAndInstall(); immediately
|
||||
setTimeout(function () {
|
||||
autoUpdater.quitAndInstall();
|
||||
}, 5000);
|
||||
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");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user