diff --git a/.changeset/flat-schools-mate.md b/.changeset/flat-schools-mate.md new file mode 100644 index 00000000000..bee47e827cf --- /dev/null +++ b/.changeset/flat-schools-mate.md @@ -0,0 +1,5 @@ +--- +"electron-updater": patch +--- + +feat: allow overriding AppUpdater.isStagingMatch diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 3e7ff8a9e0b..449711f1749 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -204,7 +204,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter this.configOnDisk = new Lazy(() => this.loadUpdateConfig()) } - protected _isUpdateSupported: VerifyUpdateSupport = (updateInfo: UpdateInfo): boolean | Promise => this.checkIfUpdateSupported(updateInfo) + protected _isUpdateSupported: VerifyUpdateSupport = updateInfo => this.checkIfUpdateSupported(updateInfo) /** * Allows developer to override default logic for determining if an update is supported. @@ -220,6 +220,23 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter } } + protected _isUserWithinRollout: VerifyUpdateSupport = updateInfo => this.isStagingMatch(updateInfo) + + /** + * Allows developer to override default logic for determining if the user is below the rollout threshold. + * The default logic compares the staging percentage with numerical representation of user ID. + * An override can define custom logic, or bypass it if needed. + */ + get isUserWithinRollout(): VerifyUpdateSupport { + return this._isUserWithinRollout + } + + set isUserWithinRollout(value: VerifyUpdateSupport) { + if (value) { + this._isUserWithinRollout = value + } + } + private clientPromise: Promise> | null = null protected readonly stagingUserIdPromise = new Lazy(() => this.getOrCreateStagingUserId()) @@ -417,8 +434,8 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter return false } - const isStagingMatch = await this.isStagingMatch(updateInfo) - if (!isStagingMatch) { + const isUserWithinRollout = await Promise.resolve(this.isUserWithinRollout(updateInfo)) + if (!isUserWithinRollout) { return false }