Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (mac) Fix intel mac upgrade flow when both x64 and arm64 published #6212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-coats-grow.md
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

Fix upgrade flows on intel mac when both x64 and arm64 versions published
11 changes: 8 additions & 3 deletions packages/electron-updater/src/MacUpdater.ts
Expand Up @@ -40,7 +40,7 @@ export class MacUpdater extends AppUpdater {

// detect if we are running inside Rosetta emulation
const sysctlRosettaInfoKey = "sysctl.proc_translated"
let isRosetta: boolean
let isRosetta = false
try {
this.debug("Checking for macOS Rosetta environment")
const result = execFileSync("sysctl", [sysctlRosettaInfoKey], { encoding: "utf8" })
Expand All @@ -50,13 +50,18 @@ export class MacUpdater extends AppUpdater {
log.warn(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`)
}

const isArm64Mac = process.arch === "arm64" || isRosetta

// allow arm64 macs to install universal or rosetta2(x64) - https://github.com/electron-userland/electron-builder/pull/5524
const isArm64 = (file: ResolvedUpdateFileInfo) => file.url.pathname.includes("arm64") || file.info.url?.includes("arm64")
if (files.some(isArm64)) {
files = files.filter(file => (process.arch === "arm64" || isRosetta) === isArm64(file))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind explaining the change you made here, @johnnyopao? From my understanding, files = files.filter(file => (process.arch === "arm64" || isRosetta) === isArm64(file)) already handles both Intel & ARM64 cases. It would be equivalent to files = files.filter(file => true === isArm64(file)) on ARM64 Macs and files = files.filter(file => false === isArm64(file)) on Intel Macs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, isRosetta could be undefined, causing the problem.

if (isArm64Mac && files.some(isArm64)) {
files = files.filter(file => isArm64Mac === isArm64(file))
} else {
files = files.filter(file => !isArm64(file))
}

const zipFileInfo = findFile(files, "zip", ["pkg", "dmg"])

if (zipFileInfo == null) {
throw newError(`ZIP file not provided: ${safeStringifyJson(files)}`, "ERR_UPDATER_ZIP_FILE_NOT_FOUND")
}
Expand Down