From e111dbbf511d491e22b8ce856b4952fd6d502d05 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 10 Apr 2025 14:54:31 -0700 Subject: [PATCH] Change auto updater to check continuously. Add Double click to tray. --- package.json | 2 +- src/main/index.ts | 40 +++++++++++++++++------------ src/main/ipc/ipcMainConfig.ts | 5 ---- src/main/ipc/ipcMainHandler.user.ts | 7 ++--- src/main/util/checkForAppUpdates.ts | 19 ++++++++++++++ 5 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 src/main/util/checkForAppUpdates.ts diff --git a/package.json b/package.json index 95e84a6..5874181 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bodyshop-desktop", - "version": "0.0.1-alpha.0", + "version": "0.0.1-alpha.2", "description": "Shop Management System Partner", "main": "./out/main/index.js", "author": "Convenient Brands, LLC", diff --git a/src/main/index.ts b/src/main/index.ts index d6a5c48..5300403 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -22,6 +22,7 @@ import ipcTypes from "../util/ipcTypes.json"; import ImportJob from "./decoder/decoder"; import LocalServer from "./http-server/http-server"; import store from "./store/store"; +import { checkForAppUpdates } from "./util/checkForAppUpdates"; import { getMainWindow } from "./util/toRenderer"; import { GetAllEnvFiles } from "./watcher/watcher"; @@ -147,6 +148,12 @@ function createWindow(): void { } }, }, + { + label: "Check for Updates", + click: (): void => { + checkForAppUpdates(); + }, + }, { label: "Development", id: "development", @@ -169,7 +176,7 @@ function createWindow(): void { { label: "Check for updates", click: (): void => { - autoUpdater.checkForUpdates(); + checkForAppUpdates(); }, }, { @@ -369,22 +376,26 @@ app.whenReady().then(async () => { }, ]); + tray.on("double-click", () => { + openMainWindow(); + }); + tray.setContextMenu(contextMenu); //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.channel = "alpha"; - autoUpdater.updateConfigPath = path.join( - __dirname, - "../../dev-app-update.yml", - ); - autoUpdater.forceDevUpdateConfig = true; - //autoUpdater.autoDownload = false; - } + // if (import.meta.env.DEV) { + // // Useful for some dev/debugging tasks, but download can + // // not be validated becuase dev app is not signed + // autoUpdater.channel = "alpha"; + // 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..."); @@ -412,11 +423,6 @@ app.whenReady().then(async () => { mainWindow?.webContents.send(ipcTypes.toRenderer.updates.downloaded, info); }); - autoUpdater.checkForUpdatesAndNotify({ - title: "Shop Partner Update", - body: "A new version of Shop Partner is available. Click to update.", - }); - //The update itself will run when the bodyshop record is queried to know what release channel to use. createWindow(); diff --git a/src/main/ipc/ipcMainConfig.ts b/src/main/ipc/ipcMainConfig.ts index 364019b..8073725 100644 --- a/src/main/ipc/ipcMainConfig.ts +++ b/src/main/ipc/ipcMainConfig.ts @@ -127,9 +127,4 @@ ipcMain.on(ipcTypes.toMain.updates.download, () => { autoUpdater.downloadUpdate(); }); -ipcMain.on(ipcTypes.toMain.updates.checkForUpdates, () => { - log.info("Checking for updates from renderer."); - autoUpdater.checkForUpdates(); -}); - logIpcMessages(); diff --git a/src/main/ipc/ipcMainHandler.user.ts b/src/main/ipc/ipcMainHandler.user.ts index 5bf6731..b97f19a 100644 --- a/src/main/ipc/ipcMainHandler.user.ts +++ b/src/main/ipc/ipcMainHandler.user.ts @@ -2,6 +2,8 @@ import { IpcMainEvent, shell } from "electron"; import log from "electron-log/main"; import { autoUpdater } from "electron-updater"; import { User } from "firebase/auth"; +import errorTypeCheck from "../../util/errorTypeCheck"; +import ipcTypes from "../../util/ipcTypes.json"; import client from "../graphql/graphql-client"; import { ActiveBodyshopQueryResult, @@ -10,9 +12,8 @@ import { QUERY_MASTERDATA_TYPED, } from "../graphql/queries"; import Store from "../store/store"; -import errorTypeCheck from "../../util/errorTypeCheck"; +import { checkForAppUpdatesContinuously } from "../util/checkForAppUpdates"; import { sendIpcToRenderer } from "../util/toRenderer"; -import ipcTypes from "../../util/ipcTypes.json"; const ipcMainHandleAuthStateChanged = async ( _event: IpcMainEvent, @@ -60,7 +61,7 @@ const ipcMainHandleAuthStateChanged = async ( "Error connecting to ImEX Online servers to get shop data. Please try again.", ); } - autoUpdater.checkForUpdatesAndNotify(); + checkForAppUpdatesContinuously(); }; const ipMainHandleResetPassword = async (): Promise => { diff --git a/src/main/util/checkForAppUpdates.ts b/src/main/util/checkForAppUpdates.ts new file mode 100644 index 0000000..26de575 --- /dev/null +++ b/src/main/util/checkForAppUpdates.ts @@ -0,0 +1,19 @@ +import { autoUpdater } from "electron-updater"; + +function checkForAppUpdatesContinuously(): void { + checkForAppUpdates(); + setInterval( + () => { + checkForAppUpdatesContinuously(); + }, + 1000 * 60 * 30, + ); +} +function checkForAppUpdates(): void { + autoUpdater.checkForUpdatesAndNotify({ + title: "Shop Partner Update", + body: "A new version of Shop Partner is available. Click to update.", + }); +} + +export { checkForAppUpdatesContinuously, checkForAppUpdates };