Add better update handler.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user