Resolve auto updater issue for mac.

This commit is contained in:
Patrick Fic
2025-04-09 15:37:45 -07:00
parent f85e007dc3
commit 6590e1a08e
5 changed files with 32 additions and 10 deletions

View File

@@ -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];

View File

@@ -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();

View File

@@ -37,7 +37,7 @@ const UpdateAvailable: React.FC = () => {
percent={updateProgress}
percentPosition={{ align: "center", type: "outer" }}
/>
{formatSpeed(updateSpeed)}
{!isUpdateComplete && formatSpeed(updateSpeed)}
{isUpdateComplete && (
<Button onClick={handleApply}>{t("updates.apply")}</Button>
)}

View File

@@ -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, () => {