Skip to content

Commit

Permalink
Allow updating mac version running inside Rosetta to native ARM (#5901)
Browse files Browse the repository at this point in the history
* Allow updating mac version running inside Rosetta to native ARM version if available
Co-authored-by: Dave Jeffery <dave@davejeffery.com>
  • Loading branch information
bartoszhernas committed May 29, 2021
1 parent d307c21 commit ef704a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/electron-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"dependencies": {
"@types/semver": "^7.3.6",
"builder-util": "workspace:*",
"builder-util-runtime": "workspace:*",
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0",
Expand Down
15 changes: 13 additions & 2 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AppUpdater, DownloadUpdateOptions } from "./AppUpdater"
import { ResolvedUpdateFileInfo } from "./main"
import { findFile } from "./providers/Provider"
import AutoUpdater = Electron.AutoUpdater
import { spawn } from "builder-util"

export class MacUpdater extends AppUpdater {
private readonly nativeUpdater: AutoUpdater = require("electron").autoUpdater
Expand All @@ -26,13 +27,23 @@ export class MacUpdater extends AppUpdater {
})
}

protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
protected async doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)

// Detect if we are running inside Rosetta emulation
const sysctlRosettaInfoKey = "sysctl.proc_translated"
let isRosetta: boolean
try {
const results = await spawn(`sysctl`, [sysctlRosettaInfoKey])
isRosetta = results?.toString()?.includes(`${sysctlRosettaInfoKey}: 1`)
} catch (e) {
this._logger.info(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`)
}

// 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")
if (files.some(isArm64)) {
files = files.filter(file => (process.arch === "arm64") === isArm64(file))
files = files.filter(file => (process.arch === "arm64" || isRosetta) === isArm64(file))
}

const zipFileInfo = findFile(files, "zip", ["pkg", "dmg"])
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef704a1

Please sign in to comment.