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..44d7ff364e 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,23 +3,12 @@ * 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 releaseChannelInjectable 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(); - - if (currentReleaseChannel in updateChannels) { - return updateChannels[currentReleaseChannel as UpdateChannelId]; - } - - return updateChannels.latest; - }, + instantiate: (di) => updateChannels[di.inject(releaseChannelInjectable)], }); export default defaultUpdateChannelInjectable; 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..78cc79cdb4 --- /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 releaseChannelInjectable = getInjectable({ + id: "release-channel", + instantiate: (di): UpdateChannelId => { + const appSemanticVersion = di.inject(appSemanticVersionInjectable); + const currentReleaseChannel = appSemanticVersion.prerelease[0]; + + switch (currentReleaseChannel) { + case "latest": + case "beta": + case "alpha": + return currentReleaseChannel; + default: + return "latest"; + } + }, +}); + +export default releaseChannelInjectable; 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/features/application-update/installing-update.test.ts b/src/features/application-update/installing-update.test.ts index 7063fcfaa1..973095d72d 100644 --- a/src/features/application-update/installing-update.test.ts +++ b/src/features/application-update/installing-update.test.ts @@ -91,7 +91,7 @@ describe("installing update", () => { it("checks for updates", () => { expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( expect.any(Object), - { allowDowngrade: true }, + { allowDowngrade: false }, ); }); diff --git a/src/features/application-update/selection-of-update-stability.test.ts b/src/features/application-update/selection-of-update-stability.test.ts index 56937ab0b4..3e7ce4a893 100644 --- a/src/features/application-update/selection-of-update-stability.test.ts +++ b/src/features/application-update/selection-of-update-stability.test.ts @@ -105,7 +105,7 @@ describe("selection of update stability", () => { it('checks updates from update channel "alpha"', () => { expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( updateChannels.alpha, - { allowDowngrade: true }, + { allowDowngrade: false }, ); }); @@ -132,7 +132,7 @@ describe("selection of update stability", () => { it('checks updates from update channel "beta"', () => { expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( updateChannels.beta, - { allowDowngrade: true }, + { allowDowngrade: false }, ); }); @@ -159,7 +159,7 @@ describe("selection of update stability", () => { it('finally checks updates from update channel "latest"', () => { expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( updateChannels.latest, - { allowDowngrade: true }, + { allowDowngrade: false }, ); }); @@ -279,7 +279,7 @@ describe("selection of update stability", () => { expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith( updateChannels.latest, - { allowDowngrade: true }, + { allowDowngrade: false }, ); }); 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..aa8fb1b131 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,24 +5,19 @@ 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 releaseChannelInjectable 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(releaseChannelInjectable); - return computed(() => { - const semVer = new SemVer(appVersion); - - return ( - semVer.prerelease[0] !== - selectedUpdateChannel.value.get().id - ); - }); + return computed(() => ( + selectedUpdateChannel.value.get().id === "latest" + && releaseChannel !== "latest" + )); }, });