Skip to content

Commit

Permalink
feat: add minimumSystemVersion in electron updater (#8108)
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp authored Mar 8, 2024
1 parent afa9755 commit 3d4cc7a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/chatty-zebras-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"builder-util-runtime": patch
"builder-util": patch
"electron-updater": patch
---

feat: add `minimumSystemVersion` in electron updater
6 changes: 6 additions & 0 deletions packages/builder-util-runtime/src/updateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export interface UpdateInfo {
* The [staged rollout](/auto-update#staged-rollouts) percentage, 0-100.
*/
readonly stagingPercentage?: number

/**
* The minimum version of system required for the app to run. Sample value: macOS `23.1.0`, Windows `10.0.22631`.
* Same with os.release() value, this is a kernel version.
*/
readonly minimumSystemVersion?: string
}

export interface WindowsUpdateInfo extends UpdateInfo {
Expand Down
14 changes: 14 additions & 0 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BlockMap,
} from "builder-util-runtime"
import { randomBytes } from "crypto"
import { release } from "os"
import { EventEmitter } from "events"
import { mkdir, outputFile, readFile, rename, unlink } from "fs-extra"
import { OutgoingHttpHeaders } from "http"
Expand Down Expand Up @@ -390,6 +391,19 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
return false
}

const minimumSystemVersion = updateInfo?.minimumSystemVersion
const currentOSVersion = release()
if (minimumSystemVersion) {
try {
if (isVersionLessThan(currentOSVersion, minimumSystemVersion)) {
this._logger.info(`Current OS version ${currentOSVersion} is less than the minimum OS version required ${minimumSystemVersion} for version ${currentOSVersion}`)
return false
}
} catch (e: any) {
this._logger.warn(`Failed to compare current OS version(${currentOSVersion}) with minimum OS version(${minimumSystemVersion}): ${(e.message || e).toString()}`)
}
}

const isStagingMatch = await this.isStagingMatch(updateInfo)
if (!isStagingMatch) {
return false
Expand Down

0 comments on commit 3d4cc7a

Please sign in to comment.