diff --git a/package.json b/package.json index 9a6d698..de69f5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bodyshop-desktop", - "version": "0.0.1-alpha.2", + "version": "0.0.1-alpha.1", "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 b294823..0727488 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -4,6 +4,7 @@ import { app, BrowserWindow, globalShortcut, + ipcMain, Menu, nativeImage, shell, @@ -371,16 +372,19 @@ 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.channel = "alpha"; // autoUpdater.updateConfigPath = path.join( // __dirname, // "../../dev-app-update.yml", // ); // autoUpdater.forceDevUpdateConfig = true; - // autoUpdater.autoDownload = false; + // //autoUpdater.autoDownload = false; // } + autoUpdater.on("checking-for-update", () => { log.info("Checking for update..."); const mainWindow = BrowserWindow.getAllWindows()[0]; @@ -406,6 +410,12 @@ app.whenReady().then(async () => { const mainWindow = BrowserWindow.getAllWindows()[0]; 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(); @@ -430,6 +440,17 @@ app.on("window-all-closed", () => { }); app.on("before-quit", () => { + preQuitMethods(); +}); + +//We need to hit the prequit methods from here as well to ensure the app quits and restarts. +ipcMain.on(ipcTypes.toMain.updates.apply, () => { + log.info("Applying update from renderer."); + preQuitMethods(); + autoUpdater.quitAndInstall(); +}); + +function preQuitMethods(): void { localServer.stop(); const currentSetting = store.get("app.openOnStartup") as boolean; store.set("app.openOnStartup", !currentSetting); @@ -442,7 +463,7 @@ app.on("before-quit", () => { } globalShortcut.unregisterAll(); isAppQuitting = true; -}); +} function openMainWindow(): void { const mainWindow = BrowserWindow.getAllWindows()[0]; diff --git a/src/main/ipc/ipcMainConfig.ts b/src/main/ipc/ipcMainConfig.ts index 93235cc..364019b 100644 --- a/src/main/ipc/ipcMainConfig.ts +++ b/src/main/ipc/ipcMainConfig.ts @@ -132,9 +132,4 @@ ipcMain.on(ipcTypes.toMain.updates.checkForUpdates, () => { autoUpdater.checkForUpdates(); }); -ipcMain.on(ipcTypes.toMain.updates.apply, () => { - log.info("Applying update from renderer."); - autoUpdater.quitAndInstall(); -}); - logIpcMessages(); diff --git a/src/renderer/src/components/UpdateAvailable/UpdateAvailable.tsx b/src/renderer/src/components/UpdateAvailable/UpdateAvailable.tsx index 9a467e6..a20a549 100644 --- a/src/renderer/src/components/UpdateAvailable/UpdateAvailable.tsx +++ b/src/renderer/src/components/UpdateAvailable/UpdateAvailable.tsx @@ -37,7 +37,7 @@ const UpdateAvailable: React.FC = () => { percent={updateProgress} percentPosition={{ align: "center", type: "outer" }} /> - {formatSpeed(updateSpeed)} + {!isUpdateComplete && formatSpeed(updateSpeed)} {isUpdateComplete && ( )} diff --git a/src/renderer/src/util/ipcRendererHandler.ts b/src/renderer/src/util/ipcRendererHandler.ts index 56a516c..c0bc704 100644 --- a/src/renderer/src/util/ipcRendererHandler.ts +++ b/src/renderer/src/util/ipcRendererHandler.ts @@ -61,7 +61,13 @@ ipcRenderer.on(ipcTypes.toRenderer.updates.available, () => { ipcRenderer.on( ipcTypes.toRenderer.updates.downloading, (_event: Electron.IpcRendererEvent, arg) => { - dispatch(updateProgress({ progress: arg.progress, speed: arg.speed })); + console.log("*** ARg", arg); + dispatch( + updateProgress({ + progress: Math.round(arg.percent), + speed: arg.bytesPerSecond, + }), + ); }, ); ipcRenderer.on(ipcTypes.toRenderer.updates.downloaded, () => {