diff --git a/apps/zui/src/domain/updates/linux-updater.ts b/apps/zui/src/domain/updates/linux-updater.ts index 76fb88020e..411f66101d 100644 --- a/apps/zui/src/domain/updates/linux-updater.ts +++ b/apps/zui/src/domain/updates/linux-updater.ts @@ -5,6 +5,7 @@ import env from "src/app/core/env" import links from "src/app/core/links" import pkg from "src/electron/pkg" import {Updater} from "./types" +import {getMainObject} from "src/core/main" export class LinuxUpdater implements Updater { async check() { @@ -29,14 +30,14 @@ export class LinuxUpdater implements Updater { } private latestUrl() { - const repo = pkg.repo + const repo = getMainObject().appMeta.repo const platform = "darwin-x64" // If the mac version exists, the linux does too return `https://update.electronjs.org/${repo}/${platform}/${app.getVersion()}` } private downloadUrl() { if (env.isInsiders) { - return pkg.repo + "/releases/latest" + return pkg.repository + "/releases/latest" } else { return links.ZUI_DOWNLOAD } diff --git a/apps/zui/src/domain/updates/mac-win-updater.ts b/apps/zui/src/domain/updates/mac-win-updater.ts index 5276a7c510..079785f698 100644 --- a/apps/zui/src/domain/updates/mac-win-updater.ts +++ b/apps/zui/src/domain/updates/mac-win-updater.ts @@ -22,25 +22,17 @@ export class MacWinUpdater implements Updater { const progress = (r) => { onProgress(r.percent / 100) } + autoUpdater.on("error", (e) => { + throw e + }) + autoUpdater.on("download-progress", progress) - let resolve - let reject - - return new Promise((res, rej) => { - resolve = res - reject = rej + return new Promise((resolve, reject) => { autoUpdater.on("update-downloaded", resolve) - autoUpdater.on("download-progress", progress) autoUpdater.on("error", reject) autoUpdater.downloadUpdate() + }).then(() => { + autoUpdater.quitAndInstall() }) - .finally(() => { - autoUpdater.off("download-progress", onProgress) - autoUpdater.off("update-downloaded", resolve) - autoUpdater.off("error", reject) - }) - .then(() => { - autoUpdater.quitAndInstall() - }) } } diff --git a/apps/zui/src/domain/updates/operations.ts b/apps/zui/src/domain/updates/operations.ts index 1ceb6f3144..16640c531f 100644 --- a/apps/zui/src/domain/updates/operations.ts +++ b/apps/zui/src/domain/updates/operations.ts @@ -10,13 +10,17 @@ export const open = createOperation("updates.open", ({main}) => { export const check = createOperation( "updates.check", async ({main, dispatch}) => { - dispatch(Updates.setIsChecking(true)) - const newVersion = await updater.check() - dispatch(Updates.setIsChecking(false)) - - if (newVersion) { - dispatch(Updates.setNextVersion(newVersion)) - main.windows.activate("update") + try { + dispatch(Updates.setIsChecking(true)) + const newVersion = await updater.check() + if (newVersion) { + dispatch(Updates.setNextVersion(newVersion)) + main.windows.activate("update") + } + } catch (e) { + dispatch(Updates.setError(errorToString(e))) + } finally { + dispatch(Updates.setIsChecking(false)) } } )