From 43d473332f9354b266351b287672d35b7a65d4e9 Mon Sep 17 00:00:00 2001 From: Jiri Zbytovsky Date: Mon, 7 Apr 2025 10:12:29 +0200 Subject: [PATCH] feat(electron-updater): add ignoreStagingPercentage option for checking updates --- packages/electron-updater/src/AppUpdater.ts | 16 ++++++++++------ packages/electron-updater/src/types.ts | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 3e7ff8a9e0b..ef790e916d4 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -35,7 +35,7 @@ import { gunzipSync } from "zlib" import { blockmapFiles } from "./util" import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader" import { GenericDifferentialDownloader } from "./differentialDownloader/GenericDifferentialDownloader" -import { DOWNLOAD_PROGRESS, Logger, ResolvedUpdateFileInfo, UPDATE_DOWNLOADED, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./types" +import { CheckForUpdatesOptions, DOWNLOAD_PROGRESS, Logger, ResolvedUpdateFileInfo, UPDATE_DOWNLOADED, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./types" import { VerifyUpdateSupport } from "./main" export type AppUpdaterEvents = { @@ -298,7 +298,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter * Asks the server whether there is an update. * @returns null if the updater is disabled, otherwise info about the latest version */ - checkForUpdates(): Promise { + checkForUpdates(options?: CheckForUpdatesOptions): Promise { if (!this.isUpdaterActive()) { return Promise.resolve(null) } @@ -312,7 +312,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter const nullizePromise = () => (this.checkForUpdatesPromise = null) this._logger.info("Checking for update") - checkForUpdatesPromise = this.doCheckForUpdates() + checkForUpdatesPromise = this.doCheckForUpdates(options) .then(it => { nullizePromise() return it @@ -399,7 +399,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter return headers } - private async isUpdateAvailable(updateInfo: UpdateInfo): Promise { + private async isUpdateAvailable(updateInfo: UpdateInfo, options?: CheckForUpdatesOptions): Promise { const latestVersion = parseVersion(updateInfo.version) if (latestVersion == null) { throw newError( @@ -417,6 +417,10 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter return false } + if (options?.ignoreStagingPercentage === true) { + return true + } + const isStagingMatch = await this.isStagingMatch(updateInfo) if (!isStagingMatch) { return false @@ -473,12 +477,12 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter } } - private async doCheckForUpdates(): Promise { + private async doCheckForUpdates(options?: CheckForUpdatesOptions): Promise { this.emit("checking-for-update") const result = await this.getUpdateInfoAndProvider() const updateInfo = result.info - if (!(await this.isUpdateAvailable(updateInfo))) { + if (!(await this.isUpdateAvailable(updateInfo, options))) { this._logger.info( `Update for version ${this.currentVersion.format()} is not available (latest version: ${updateInfo.version}, downgrade is ${ this.allowDowngrade ? "allowed" : "disallowed" diff --git a/packages/electron-updater/src/types.ts b/packages/electron-updater/src/types.ts index d4e92de3c24..496612bb5e1 100644 --- a/packages/electron-updater/src/types.ts +++ b/packages/electron-updater/src/types.ts @@ -81,3 +81,7 @@ export interface ResolvedUpdateFileInfo { export type UpdaterEvents = "login" | "checking-for-update" | "update-available" | "update-not-available" | "update-cancelled" | "download-progress" | "update-downloaded" | "error" export type LoginHandler = (authInfo: any, callback: LoginCallback) => void + +export type CheckForUpdatesOptions = { + ignoreStagingPercentage?: boolean +}