Skip to content

Commit cf43f05

Browse files
authored
feat(electron-updater): allow overriding AppUpdater.isStagingMatch with hook isUserWithinRollout (#9021)
1 parent 8bd1a10 commit cf43f05

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.changeset/flat-schools-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-updater": patch
3+
---
4+
5+
feat: allow overriding AppUpdater.isStagingMatch

packages/electron-updater/src/AppUpdater.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
204204
this.configOnDisk = new Lazy<any>(() => this.loadUpdateConfig())
205205
}
206206

207-
protected _isUpdateSupported: VerifyUpdateSupport = (updateInfo: UpdateInfo): boolean | Promise<boolean> => this.checkIfUpdateSupported(updateInfo)
207+
protected _isUpdateSupported: VerifyUpdateSupport = updateInfo => this.checkIfUpdateSupported(updateInfo)
208208

209209
/**
210210
* 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
220220
}
221221
}
222222

223+
protected _isUserWithinRollout: VerifyUpdateSupport = updateInfo => this.isStagingMatch(updateInfo)
224+
225+
/**
226+
* Allows developer to override default logic for determining if the user is below the rollout threshold.
227+
* The default logic compares the staging percentage with numerical representation of user ID.
228+
* An override can define custom logic, or bypass it if needed.
229+
*/
230+
get isUserWithinRollout(): VerifyUpdateSupport {
231+
return this._isUserWithinRollout
232+
}
233+
234+
set isUserWithinRollout(value: VerifyUpdateSupport) {
235+
if (value) {
236+
this._isUserWithinRollout = value
237+
}
238+
}
239+
223240
private clientPromise: Promise<Provider<any>> | null = null
224241

225242
protected readonly stagingUserIdPromise = new Lazy<string>(() => this.getOrCreateStagingUserId())
@@ -417,8 +434,8 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
417434
return false
418435
}
419436

420-
const isStagingMatch = await this.isStagingMatch(updateInfo)
421-
if (!isStagingMatch) {
437+
const isUserWithinRollout = await Promise.resolve(this.isUserWithinRollout(updateInfo))
438+
if (!isUserWithinRollout) {
422439
return false
423440
}
424441

0 commit comments

Comments
 (0)