From 5bf44987412189783e9b7ebbc35376ce471362c6 Mon Sep 17 00:00:00 2001 From: Neil Rees <282424+neilrees@users.noreply.github.com> Date: Mon, 23 Sep 2019 06:57:04 +0100 Subject: [PATCH] fix(electron-updater): when AllowDowngrade is true and latest version is older, take the update (#4218) --- packages/electron-updater/src/AppUpdater.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index d51558c6e09..c2b133f1e2d 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -7,7 +7,7 @@ import { OutgoingHttpHeaders } from "http" import { safeLoad } from "js-yaml" import { Lazy } from "lazy-val" import * as path from "path" -import { eq as isVersionsEqual, gt as isVersionGreaterThan, parse as parseVersion, prerelease as getVersionPreleaseComponents, SemVer } from "semver" +import { eq as isVersionsEqual, gt as isVersionGreaterThan, lt as isVersionLessThan, parse as parseVersion, prerelease as getVersionPreleaseComponents, SemVer } from "semver" import { AppAdapter } from "./AppAdapter" import { createTempUpdateFile, DownloadedUpdateHelper } from "./DownloadedUpdateHelper" import { ElectronAppAdapter } from "./ElectronAppAdapter" @@ -317,18 +317,17 @@ export abstract class AppUpdater extends EventEmitter { // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405033227 // https://github.com/electron-userland/electron-builder/pull/3111#issuecomment-405030797 const isLatestVersionNewer = isVersionGreaterThan(latestVersion, currentVersion) - if (!this.allowDowngrade) { - return isLatestVersionNewer + const isLatestVersionOlder = isVersionLessThan(latestVersion, currentVersion) + + if (isLatestVersionNewer) { + return true } - const currentVersionPrereleaseComponent = getVersionPreleaseComponents(currentVersion) - const latestVersionPrereleaseComponent = getVersionPreleaseComponents(latestVersion) - if (currentVersionPrereleaseComponent === latestVersionPrereleaseComponent) { - // allowDowngrade taken in account only if channel differs - return isLatestVersionNewer + if (this.allowDowngrade && isLatestVersionOlder) { + return true } - return true + return false } protected async getUpdateInfoAndProvider(): Promise {