Skip to content
Closed
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
16 changes: 10 additions & 6 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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<UpdateCheckResult | null> {
checkForUpdates(options?: CheckForUpdatesOptions): Promise<UpdateCheckResult | null> {
if (!this.isUpdaterActive()) {
return Promise.resolve(null)
}
Expand All @@ -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
Expand Down Expand Up @@ -399,7 +399,7 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
return headers
}

private async isUpdateAvailable(updateInfo: UpdateInfo): Promise<boolean> {
private async isUpdateAvailable(updateInfo: UpdateInfo, options?: CheckForUpdatesOptions): Promise<boolean> {
const latestVersion = parseVersion(updateInfo.version)
if (latestVersion == null) {
throw newError(
Expand All @@ -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
Expand Down Expand Up @@ -473,12 +477,12 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter
}
}

private async doCheckForUpdates(): Promise<UpdateCheckResult> {
private async doCheckForUpdates(options?: CheckForUpdatesOptions): Promise<UpdateCheckResult> {
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"
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-updater/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}