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

feat: add minimumSystemVersion in electron updater #8108

Merged
merged 7 commits into from
Mar 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()}`)
}
}
mmaietta marked this conversation as resolved.
Show resolved Hide resolved

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