Skip to content

Commit 0a83ebf

Browse files
committed
Merge remote-tracking branch 'origin/master' into explore/vitest-rollup-2
# Conflicts: # packages/electron-updater/src/AppUpdater.ts # packages/electron-updater/src/NsisUpdater.ts # packages/electron-updater/src/main.ts
2 parents e0c3db7 + 96c5d14 commit 0a83ebf

File tree

8 files changed

+84
-24
lines changed

8 files changed

+84
-24
lines changed

.changeset/fuzzy-trains-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-updater": minor
3+
---
4+
5+
feat: add `isUpdateAvailable` property to `checkForUpdates` result

.changeset/smart-starfishes-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-updater": minor
3+
---
4+
5+
feat: add support for custom `isUpdateSupported` hook for validating `UpdateInfo`, with fallback to previous `minimumSystemVersion` logic

.changeset/weak-owls-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix: handle yarn berry patch format in electron-updater version check

packages/app-builder-lib/src/util/packageMetadata.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,23 @@ function checkDependencies(dependencies: Record<string, string> | Nullish, error
9898
return
9999
}
100100

101-
const updaterVersion = dependencies["electron-updater"]
102-
const requiredElectronUpdaterVersion = "4.0.0"
103-
if (updaterVersion != null && !versionSatisfies(updaterVersion, `>=${requiredElectronUpdaterVersion}`)) {
104-
errors.push(
105-
`At least electron-updater ${requiredElectronUpdaterVersion} is recommended by current electron-builder version. Please set electron-updater version to "^${requiredElectronUpdaterVersion}"`
106-
)
101+
let updaterVersion = dependencies["electron-updater"]
102+
if (updaterVersion != null) {
103+
// Pick the version out of yarn berry patch syntax
104+
// "patch:electron-updater@npm%3A6.4.1#~/.yarn/patches/electron-updater-npm-6.4.1-ef33e6cc39.patch"
105+
if (updaterVersion.startsWith('patch:')) {
106+
const match = updaterVersion.match(/@npm%3A(.+?)#/)
107+
if (match) {
108+
updaterVersion = match[1]
109+
}
110+
}
111+
112+
const requiredElectronUpdaterVersion = "4.0.0"
113+
if (!versionSatisfies(updaterVersion, `>=${requiredElectronUpdaterVersion}`)) {
114+
errors.push(
115+
`At least electron-updater ${requiredElectronUpdaterVersion} is recommended by current electron-builder version. Please set electron-updater version to "^${requiredElectronUpdaterVersion}"`
116+
)
117+
}
107118
}
108119

109120
const swVersion = dependencies["electron-builder-squirrel-windows"]

packages/electron-updater/src/AppUpdater.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { blockmapFiles } from "./util"
3636
import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader"
3737
import { GenericDifferentialDownloader } from "./differentialDownloader/GenericDifferentialDownloader"
3838
import { DOWNLOAD_PROGRESS, Logger, ResolvedUpdateFileInfo, UPDATE_DOWNLOADED, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./exports"
39+
import { VerifyUpdateSupport } from "./main"
3940

4041
export type AppUpdaterEvents = {
4142
error: (error: Error, message?: string) => void
@@ -203,6 +204,22 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
203204
this.configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())
204205
}
205206

207+
protected _isUpdateSupported: VerifyUpdateSupport = (updateInfo: UpdateInfo): boolean | Promise<boolean> => this.checkIfUpdateSupported(updateInfo)
208+
209+
/**
210+
* Allows developer to override default logic for determining if an update is supported.
211+
* The default logic compares the `UpdateInfo` minimum system version against the `os.release()` with `semver` package
212+
*/
213+
get isUpdateSupported(): VerifyUpdateSupport {
214+
return this._isUpdateSupported
215+
}
216+
217+
set isUpdateSupported(value: VerifyUpdateSupport) {
218+
if (value) {
219+
this._isUpdateSupported = value
220+
}
221+
}
222+
206223
private clientPromise: Promise<Provider<any>> | null = null
207224

208225
protected readonly stagingUserIdPromise = new Lazy<string>(() => this.getOrCreateStagingUserId())
@@ -279,6 +296,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
279296

280297
/**
281298
* Asks the server whether there is an update.
299+
* @returns null if the updater is disabled, otherwise info about the latest version
282300
*/
283301
checkForUpdates(): Promise<UpdateCheckResult | null> {
284302
if (!this.isUpdaterActive()) {
@@ -395,17 +413,8 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
395413
return false
396414
}
397415

398-
const minimumSystemVersion = updateInfo?.minimumSystemVersion
399-
const currentOSVersion = release()
400-
if (minimumSystemVersion) {
401-
try {
402-
if (isVersionLessThan(currentOSVersion, minimumSystemVersion)) {
403-
this._logger.info(`Current OS version ${currentOSVersion} is less than the minimum OS version required ${minimumSystemVersion} for version ${currentOSVersion}`)
404-
return false
405-
}
406-
} catch (e: any) {
407-
this._logger.warn(`Failed to compare current OS version(${currentOSVersion}) with minimum OS version(${minimumSystemVersion}): ${(e.message || e).toString()}`)
408-
}
416+
if (!(await Promise.resolve(this.isUpdateSupported(updateInfo)))) {
417+
return false
409418
}
410419

411420
const isStagingMatch = await this.isStagingMatch(updateInfo)
@@ -424,6 +433,22 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
424433
return this.allowDowngrade && isLatestVersionOlder
425434
}
426435

436+
private checkIfUpdateSupported(updateInfo: UpdateInfo) {
437+
const minimumSystemVersion = updateInfo?.minimumSystemVersion
438+
const currentOSVersion = release()
439+
if (minimumSystemVersion) {
440+
try {
441+
if (isVersionLessThan(currentOSVersion, minimumSystemVersion)) {
442+
this._logger.info(`Current OS version ${currentOSVersion} is less than the minimum OS version required ${minimumSystemVersion} for version ${currentOSVersion}`)
443+
return false
444+
}
445+
} catch (e: any) {
446+
this._logger.warn(`Failed to compare current OS version(${currentOSVersion}) with minimum OS version(${minimumSystemVersion}): ${(e.message || e).toString()}`)
447+
}
448+
}
449+
return true
450+
}
451+
427452
protected async getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider> {
428453
await this.app.whenReady()
429454

@@ -461,6 +486,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
461486
)
462487
this.emit("update-not-available", updateInfo)
463488
return {
489+
isUpdateAvailable: false,
464490
versionInfo: updateInfo,
465491
updateInfo,
466492
}
@@ -472,6 +498,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
472498
const cancellationToken = new CancellationToken()
473499
//noinspection ES6MissingAwait
474500
return {
501+
isUpdateAvailable: true,
475502
versionInfo: updateInfo,
476503
updateInfo,
477504
cancellationToken,

packages/electron-updater/src/NsisUpdater.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { DownloadUpdateOptions } from "./AppUpdater"
55
import { BaseUpdater, InstallOptions } from "./BaseUpdater"
66
import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader"
77
import { FileWithEmbeddedBlockMapDifferentialDownloader } from "./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader"
8-
import { verifyUpdateCodeSignature } from "./main"
98
import { DOWNLOAD_PROGRESS } from "./exports"
9+
import { VerifyUpdateCodeSignature } from "./main"
1010
import { findFile, Provider } from "./providers/Provider"
1111
import { unlink } from "fs-extra"
1212
import { verifySignature } from "./windowsExecutableCodeSignatureVerifier"
@@ -23,18 +23,18 @@ export class NsisUpdater extends BaseUpdater {
2323
super(options, app)
2424
}
2525

26-
protected _verifyUpdateCodeSignature: verifyUpdateCodeSignature = (publisherNames: Array<string>, unescapedTempUpdateFile: string) =>
26+
protected _verifyUpdateCodeSignature: VerifyUpdateCodeSignature = (publisherNames: Array<string>, unescapedTempUpdateFile: string) =>
2727
verifySignature(publisherNames, unescapedTempUpdateFile, this._logger)
2828

2929
/**
3030
* The verifyUpdateCodeSignature. You can pass [win-verify-signature](https://github.com/beyondkmp/win-verify-trust) or another custom verify function: ` (publisherName: string[], path: string) => Promise<string | null>`.
3131
* The default verify function uses [windowsExecutableCodeSignatureVerifier](https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts)
3232
*/
33-
get verifyUpdateCodeSignature(): verifyUpdateCodeSignature {
33+
get verifyUpdateCodeSignature(): VerifyUpdateCodeSignature {
3434
return this._verifyUpdateCodeSignature
3535
}
3636

37-
set verifyUpdateCodeSignature(value: verifyUpdateCodeSignature) {
37+
set verifyUpdateCodeSignature(value: VerifyUpdateCodeSignature) {
3838
if (value) {
3939
this._verifyUpdateCodeSignature = value
4040
}

packages/electron-updater/src/exports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export function addHandler(emitter: EventEmitter, event: UpdaterEvents, handler:
5353
}
5454

5555
export interface UpdateCheckResult {
56+
readonly isUpdateAvailable: boolean
57+
5658
readonly updateInfo: UpdateInfo
5759

5860
readonly downloadPromise?: Promise<Array<string>> | null

packages/electron-updater/src/main.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { existsSync, readFileSync } from "fs-extra"
22
import * as path from "path"
33
import { AppUpdater } from "./AppUpdater"
4+
import { UpdateInfo } from "builder-util-runtime"
45

56
export { BaseUpdater } from "./BaseUpdater"
67
export { AppUpdater, NoOpLogger } from "./AppUpdater"
@@ -66,6 +67,10 @@ Object.defineProperty(exports, "autoUpdater", {
6667
},
6768
})
6869

69-
// return null if verify signature succeed
70-
// return error message if verify signature failed
71-
export type verifyUpdateCodeSignature = (publisherName: string[], path: string) => Promise<string | null>
70+
/**
71+
* return null if verify signature succeed
72+
* return error message if verify signature failed
73+
*/
74+
export type VerifyUpdateCodeSignature = (publisherName: string[], path: string) => Promise<string | null>
75+
76+
export type VerifyUpdateSupport = (updateInfo: UpdateInfo) => boolean | Promise<boolean>

0 commit comments

Comments
 (0)