diff --git a/electron/main.js b/electron/main.js index 6e01a3d..832b244 100644 --- a/electron/main.js +++ b/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"); + } + } + ); + } }); diff --git a/package-lock.json b/package-lock.json index a602e33..7e6cc99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6440,8 +6440,7 @@ "deep-diff": { "version": "0.3.8", "resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-0.3.8.tgz", - "integrity": "sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ=", - "dev": true + "integrity": "sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ=" }, "deep-equal": { "version": "1.1.1", @@ -16551,7 +16550,6 @@ "version": "3.0.6", "resolved": "https://registry.npmjs.org/redux-logger/-/redux-logger-3.0.6.tgz", "integrity": "sha1-91VZZvMJjzyIYExEnPC69XeCdL8=", - "dev": true, "requires": { "deep-diff": "^0.3.5" } diff --git a/package.json b/package.json index c129288..b1895c6 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "react-scripts": "3.4.3", "recharts": "^1.8.5", "redux": "^4.0.5", + "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-saga": "^1.1.3", "reselect": "^4.0.0", @@ -48,8 +49,10 @@ "dev": "concurrently -k \"npm start\" \"npm:electron\"", "electron": "wait-on tcp:3000 && electron .", "pack": "electron-builder --dir", - "dist": "electron-builder", - "postinstall": "electron-builder install-app-deps" + "dist": "npm run build && electron-builder", + "distp": "npm run build && electron-builder --publish always", + "distpnb": "npm run build && electron-builder --publish always", + "postinstall": "npm run build && electron-builder install-app-deps" }, "eslintConfig": { "extends": "react-app" @@ -73,24 +76,23 @@ "electron-devtools-installer": "^3.1.1", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.5", - "redux-logger": "^3.0.6", "wait-on": "^5.2.0" }, "build": { "extends": null, "appId": "com.imex.rps", + "copyright": "Copyright © Snapt Software Inc.", "files": [ "build/**", "electron/**", "src/ipc.types.js", "src/assets/**" ], - "publish": [ - { - "provider": "generic", - "url": "https://update.rps.bodyshop.app" - } - ], + "publish": { + "provider": "s3", + "bucket": "rps-updater", + "region": "ca-central-1" + }, "win": { "target": "nsis", "icon": "src/icons/win/icon.ico"