Added electron builder and auto update scripts. Scripts not tested.

This commit is contained in:
Patrick Fic
2020-10-15 16:59:44 -07:00
parent e6d1c7188b
commit 827243e11f
6 changed files with 1078 additions and 26 deletions

View File

@@ -3,8 +3,14 @@ const { app, BrowserWindow, Tray, Menu, ipcMain } = 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");
require("./ipc-main-handler");
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
log.info("App starting...");
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension, REACT_DEVELOPER_TOOLS;
if (isDev) {
@@ -29,6 +35,7 @@ function createWindow() {
webPreferences: {
nodeIntegration: false,
enableRemoteModule: false,
webSecurity: false,
worldSafeExecuteJavaScript: true,
contextIsolation: true,
preload: path.join(__dirname, "preload.js"), // use a preload script
@@ -39,7 +46,7 @@ function createWindow() {
mainWindow.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "../build/index.html")}`
: `file://${path.join(__dirname, "/../build/index.html")}`
);
// mainWindow.on("close", function (event) {
@@ -67,6 +74,7 @@ function createWindow() {
}
mainWindow.maximize();
autoUpdater.checkForUpdatesAndNotify();
}
exports.mainWindow = mainWindow;
@@ -90,6 +98,7 @@ app.whenReady().then(() => {
});
if (isDev) app.setAppUserModelId(process.execPath);
else app.setAppUserModelId("com.imex.rps");
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
@@ -147,3 +156,30 @@ function createTray() {
appIcon.setContextMenu(contextMenu);
return appIcon;
}
autoUpdater.on("checking-for-update", () => {
console.log("Checking for update...");
});
autoUpdater.on("update-available", (ev, info) => {
console.log("Update available.");
});
autoUpdater.on("update-not-available", (ev, info) => {
console.log("Update not available.");
});
autoUpdater.on("error", (ev, err) => {
console.log("Error in auto-updater.");
});
autoUpdater.on("download-progress", (ev, progressObj) => {
console.log("Download progress...");
});
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);
});

View File

@@ -3,6 +3,7 @@ const path = require("path");
function NewNotification(config) {
return Notification({
icon: path.join(__dirname, "../../src/assets/logo512.png"),
...config,
});