Skip to content

Commit

Permalink
fix(mac): Allow arm64 macs to update to x64 version if no arm64 versi…
Browse files Browse the repository at this point in the history
…on available (#5524)

* fix(mac): Allow arm64 macs to update to x64 version if no arm64 version available

* fix reassignment

* lint

* Add explainer comment

* move comment
  • Loading branch information
davej authored Jan 15, 2021
1 parent ced6e50 commit dc5c2f8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createServer, IncomingMessage, ServerResponse } from "http"
import { AddressInfo } from "net"
import { AppAdapter } from "./AppAdapter"
import { AppUpdater, DownloadUpdateOptions } from "./AppUpdater"
import { UpdateDownloadedEvent } from "./main"
import { ResolvedUpdateFileInfo, UpdateDownloadedEvent } from "./main"
import { findFile } from "./providers/Provider"
import AutoUpdater = Electron.AutoUpdater

Expand All @@ -31,8 +31,14 @@ export class MacUpdater extends AppUpdater {
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {
this.updateInfoForPendingUpdateDownloadedEvent = null

const files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)
.filter(file => (process.arch == 'arm64') === (file.url.pathname.includes('arm64')));
let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info);

// 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));
}

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

0 comments on commit dc5c2f8

Please sign in to comment.