Skip to content

Commit

Permalink
fix(electron-updater): when AllowDowngrade is true and latest version…
Browse files Browse the repository at this point in the history
… is older, take the update (#4218)
  • Loading branch information
neilrees authored and develar committed Sep 23, 2019
1 parent 1d21620 commit 5bf4498
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<UpdateInfoAndProvider> {
Expand Down

0 comments on commit 5bf4498

Please sign in to comment.