Add better update handler.
This commit is contained in:
@@ -45,7 +45,7 @@ const DecodeAD2 = async (
|
||||
"CLMT_PH2",
|
||||
"CLMT_PH2X",
|
||||
"CLMT_FAX",
|
||||
"CLMT_FAXX",
|
||||
//"CLMT_FAXX",
|
||||
"CLMT_EA",
|
||||
//"EST_CO_ID",
|
||||
"EST_CO_NM",
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
|
||||
import { app, BrowserWindow, Menu, shell } from "electron";
|
||||
import log from "electron-log/main";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import path, { join } from "path";
|
||||
import icon from "../../resources/icon.png?asset";
|
||||
import ErrorTypeCheck from "../util/errorTypeCheck";
|
||||
import ipcTypes from "../util/ipcTypes.json";
|
||||
import client from "./graphql/graphql-client";
|
||||
import store from "./store/store";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import { createPublicKey } from "crypto";
|
||||
|
||||
log.initialize();
|
||||
const isMac = process.platform === "darwin";
|
||||
@@ -131,6 +133,12 @@ function createWindow(): void {
|
||||
{
|
||||
label: "Development",
|
||||
submenu: [
|
||||
{
|
||||
label: "Check for updates",
|
||||
click: (): void => {
|
||||
autoUpdater.checkForUpdates();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Open Log Folder",
|
||||
click: (): void => {
|
||||
@@ -251,6 +259,42 @@ app.whenReady().then(async () => {
|
||||
//Check for app updates.
|
||||
|
||||
autoUpdater.logger = log;
|
||||
if (import.meta.env.DEV) {
|
||||
// Useful for some dev/debugging tasks, but download can
|
||||
// not be validated becuase dev app is not signed
|
||||
autoUpdater.updateConfigPath = path.join(
|
||||
__dirname,
|
||||
"../../dev-app-update.yml",
|
||||
);
|
||||
autoUpdater.forceDevUpdateConfig = true;
|
||||
autoUpdater.autoDownload = false;
|
||||
}
|
||||
autoUpdater.on("checking-for-update", () => {
|
||||
log.info("Checking for update...");
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.checking);
|
||||
});
|
||||
autoUpdater.on("update-available", (info) => {
|
||||
log.info("Update available.", info);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.available, info);
|
||||
});
|
||||
autoUpdater.on("download-progress", (progress) => {
|
||||
log.info(`Download speed: ${progress.bytesPerSecond}`);
|
||||
log.info(`Downloaded ${progress.percent}%`);
|
||||
log.info(`Total downloaded ${progress.transferred}/${progress.total}`);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
mainWindow?.webContents.send(
|
||||
ipcTypes.toRenderer.updates.downloading,
|
||||
progress,
|
||||
);
|
||||
});
|
||||
autoUpdater.on("update-downloaded", (info) => {
|
||||
log.info("Update downloaded", info);
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0];
|
||||
mainWindow?.webContents.send(ipcTypes.toRenderer.updates.downloaded, info);
|
||||
});
|
||||
//autoUpdater.checkForUpdates();
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
createWindow();
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
SettingsWatchedFilePathsRemove,
|
||||
} from "./ipcMainHandler.settings";
|
||||
import { ipcMainHandleAuthStateChanged } from "./ipcMainHandler.user";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
|
||||
// Log all IPC messages and their payloads
|
||||
const logIpcMessages = (): void => {
|
||||
@@ -87,4 +88,19 @@ ipcMain.on(ipcTypes.toMain.watcher.stop, () => {
|
||||
StopWatcher();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.updates.download, () => {
|
||||
log.info("Download update requested from renderer.");
|
||||
autoUpdater.downloadUpdate();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.updates.checkForUpdates, () => {
|
||||
log.info("Checking for updates from renderer.");
|
||||
autoUpdater.checkForUpdates();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.updates.apply, () => {
|
||||
log.info("Applying update from renderer.");
|
||||
autoUpdater.quitAndInstall();
|
||||
});
|
||||
|
||||
logIpcMessages();
|
||||
|
||||
Reference in New Issue
Block a user