From a2c591f580d70c61c9ef6419c80572b57722b9a5 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 6 Sep 2022 13:48:51 -0400 Subject: [PATCH] Fix beta->latest->beta upgrade loop Signed-off-by: Sebastian Malton --- .../default-update-channel.injectable.ts | 12 ++--- .../application-update/update-channels.ts | 2 +- src/common/vars/release-channel.injectable.ts | 26 +++++++++++ .../downgrading-version-update.test.ts | 45 ++++++++++++++++--- ...pdates-starting-from-channel.injectable.ts | 5 +-- .../update-can-be-downgraded.injectable.ts | 20 +++++---- 6 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 src/common/vars/release-channel.injectable.ts diff --git a/src/common/application-update/selected-update-channel/default-update-channel.injectable.ts b/src/common/application-update/selected-update-channel/default-update-channel.injectable.ts index 90dc22457a..57561f03b3 100644 --- a/src/common/application-update/selected-update-channel/default-update-channel.injectable.ts +++ b/src/common/application-update/selected-update-channel/default-update-channel.injectable.ts @@ -3,22 +3,16 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import appSemanticVersionInjectable from "../../vars/app-semantic-version.injectable"; -import type { UpdateChannelId } from "../update-channels"; +import currentReleaseIdInjectable from "../../vars/release-channel.injectable"; import { updateChannels } from "../update-channels"; const defaultUpdateChannelInjectable = getInjectable({ id: "default-update-channel", instantiate: (di) => { - const appSemanticVersion = di.inject(appSemanticVersionInjectable); - const currentReleaseChannel = appSemanticVersion.prerelease[0]?.toString(); + const currentReleaseId = di.inject(currentReleaseIdInjectable); - if (currentReleaseChannel in updateChannels) { - return updateChannels[currentReleaseChannel as UpdateChannelId]; - } - - return updateChannels.latest; + return updateChannels[currentReleaseId ?? "latest"]; }, }); diff --git a/src/common/application-update/update-channels.ts b/src/common/application-update/update-channels.ts index dff1e5879e..5d166eabdb 100644 --- a/src/common/application-update/update-channels.ts +++ b/src/common/application-update/update-channels.ts @@ -24,7 +24,7 @@ const alphaChannel: UpdateChannel = { moreStableUpdateChannel: betaChannel, }; -export const updateChannels: Record = { +export const updateChannels = { latest: latestChannel, beta: betaChannel, alpha: alphaChannel, diff --git a/src/common/vars/release-channel.injectable.ts b/src/common/vars/release-channel.injectable.ts new file mode 100644 index 0000000000..00949e2a2c --- /dev/null +++ b/src/common/vars/release-channel.injectable.ts @@ -0,0 +1,26 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable } from "@ogre-tools/injectable"; +import type { UpdateChannelId } from "../application-update/update-channels"; +import appSemanticVersionInjectable from "./app-semantic-version.injectable"; + +const currentReleaseIdInjectable = getInjectable({ + id: "release-channel", + instantiate: (di): UpdateChannelId | undefined => { + const appSemanticVersion = di.inject(appSemanticVersionInjectable); + const currentReleaseChannel = appSemanticVersion.prerelease[0]; + + switch (currentReleaseChannel) { + case "latest": + case "beta": + case "alpha": + return currentReleaseChannel; + default: + return undefined; + } + }, +}); + +export default currentReleaseIdInjectable; diff --git a/src/features/application-update/downgrading-version-update.test.ts b/src/features/application-update/downgrading-version-update.test.ts index 0462bee3d4..eb35e84be9 100644 --- a/src/features/application-update/downgrading-version-update.test.ts +++ b/src/features/application-update/downgrading-version-update.test.ts @@ -40,6 +40,36 @@ describe("downgrading version update", () => { }); [ + { + updateChannel: updateChannels.latest, + appVersion: "4.0.0", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.beta, + appVersion: "4.0.0", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.alpha, + appVersion: "4.0.0", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.latest, + appVersion: "4.0.0-latest", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.beta, + appVersion: "4.0.0-latest", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.alpha, + appVersion: "4.0.0-latest", + downgradeIsAllowed: false, + }, { updateChannel: updateChannels.latest, appVersion: "4.0.0-beta", @@ -50,16 +80,21 @@ describe("downgrading version update", () => { appVersion: "4.0.0-beta", downgradeIsAllowed: false, }, - { - updateChannel: updateChannels.beta, - appVersion: "4.0.0-beta.1", - downgradeIsAllowed: false, - }, { updateChannel: updateChannels.alpha, appVersion: "4.0.0-beta", + downgradeIsAllowed: false, + }, + { + updateChannel: updateChannels.latest, + appVersion: "4.0.0-alpha", downgradeIsAllowed: true, }, + { + updateChannel: updateChannels.beta, + appVersion: "4.0.0-alpha", + downgradeIsAllowed: false, + }, { updateChannel: updateChannels.alpha, appVersion: "4.0.0-alpha", diff --git a/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts b/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts index caf695ff80..0381c883a6 100644 --- a/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts +++ b/src/main/application-update/check-for-updates/check-for-updates-starting-from-channel.injectable.ts @@ -19,10 +19,7 @@ const checkForUpdatesStartingFromChannelInjectable = getInjectable({ id: "check-for-updates-starting-from-channel", instantiate: (di) => { - const checkForPlatformUpdates = di.inject( - checkForPlatformUpdatesInjectable, - ); - + const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable); const updateCanBeDowngraded = di.inject(updateCanBeDowngradedInjectable); const _recursiveCheck = async ( diff --git a/src/main/application-update/check-for-updates/update-can-be-downgraded.injectable.ts b/src/main/application-update/check-for-updates/update-can-be-downgraded.injectable.ts index 08fd1d933d..ff4179b2d2 100644 --- a/src/main/application-update/check-for-updates/update-can-be-downgraded.injectable.ts +++ b/src/main/application-update/check-for-updates/update-can-be-downgraded.injectable.ts @@ -5,23 +5,27 @@ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable"; -import appVersionInjectable from "../../../common/vars/app-version.injectable"; -import { SemVer } from "semver"; +import currentReleaseIdInjectable from "../../../common/vars/release-channel.injectable"; const updateCanBeDowngradedInjectable = getInjectable({ id: "update-can-be-downgraded", instantiate: (di) => { const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable); - const appVersion = di.inject(appVersionInjectable); + const releaseChannel = di.inject(currentReleaseIdInjectable); return computed(() => { - const semVer = new SemVer(appVersion); + if (!releaseChannel) { + return false; + } - return ( - semVer.prerelease[0] !== - selectedUpdateChannel.value.get().id - ); + const currentSelectedChannel = selectedUpdateChannel.value.get().id; + + if (currentSelectedChannel !== "latest") { + return false; + } + + return releaseChannel !== "latest"; }); }, });