Skip to content

Commit

Permalink
Fix up linux and mac updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskerr committed Nov 1, 2023
1 parent 0f4c1b9 commit acb5267
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
5 changes: 3 additions & 2 deletions apps/zui/src/domain/updates/linux-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Expand Down
22 changes: 7 additions & 15 deletions apps/zui/src/domain/updates/mac-win-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
}
18 changes: 11 additions & 7 deletions apps/zui/src/domain/updates/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
)
Expand Down

0 comments on commit acb5267

Please sign in to comment.