diff --git a/src/behaviours/update-app/downgrading-version-update.test.ts b/src/behaviours/update-app/downgrading-version-update.test.ts index 0b448b5c64..125b899223 100644 --- a/src/behaviours/update-app/downgrading-version-update.test.ts +++ b/src/behaviours/update-app/downgrading-version-update.test.ts @@ -11,10 +11,10 @@ import asyncFn from "@async-fn/jest"; import type { CheckForPlatformUpdates } from "../../main/update-app/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "../../main/update-app/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForUpdatesInjectable from "../../main/update-app/check-for-updates/check-for-updates.injectable"; -import selectedUpdateChannelInjectable from "../../main/update-app/selected-update-channel.injectable"; +import selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; import appVersionInjectable from "../../common/get-configuration-file-model/app-version/app-version.injectable"; -import { updateChannels } from "../../main/update-app/update-channels"; +import { updateChannels } from "../../common/application-update/update-channels"; describe("downgrading version update", () => { let applicationBuilder: ApplicationBuilder; diff --git a/src/behaviours/update-app/installing-update.test.ts b/src/behaviours/update-app/installing-update.test.ts index deba5ea3a2..f522a2fe8e 100644 --- a/src/behaviours/update-app/installing-update.test.ts +++ b/src/behaviours/update-app/installing-update.test.ts @@ -12,11 +12,11 @@ import type { CheckForPlatformUpdates } from "../../main/update-app/check-for-pl import checkForPlatformUpdatesInjectable from "../../main/update-app/check-for-platform-updates/check-for-platform-updates.injectable"; import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; -import type { UpdateChannel, UpdateChannelId } from "../../main/update-app/update-channels"; -import { updateChannels } from "../../main/update-app/update-channels"; +import type { UpdateChannel, UpdateChannelId } from "../../common/application-update/update-channels"; +import { updateChannels } from "../../common/application-update/update-channels"; import type { DownloadPlatformUpdate } from "../../main/update-app/download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "../../main/update-app/download-platform-update/download-platform-update.injectable"; -import selectedUpdateChannelInjectable from "../../main/update-app/selected-update-channel.injectable"; +import selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import type { IComputedValue } from "mobx"; import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; import type { AskBoolean } from "../../main/ask-boolean/ask-boolean.injectable"; diff --git a/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts b/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts index 75f6d42dd6..218fe96c70 100644 --- a/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts +++ b/src/common/application-update/discovered-update-version/discovered-update-version.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable"; -import type { UpdateChannel } from "../../../main/update-app/update-channels"; +import type { UpdateChannel } from "../update-channels"; const discoveredUpdateVersionInjectable = getInjectable({ id: "discovered-update-version", diff --git a/src/common/application-update/selected-update-channel/selected-update-channel.injectable.ts b/src/common/application-update/selected-update-channel/selected-update-channel.injectable.ts new file mode 100644 index 0000000000..69370d76c6 --- /dev/null +++ b/src/common/application-update/selected-update-channel/selected-update-channel.injectable.ts @@ -0,0 +1,51 @@ +/** + * 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 { IComputedValue } from "mobx"; +import { action, computed, observable } from "mobx"; +import type { UpdateChannel, UpdateChannelId } from "../update-channels"; +import { updateChannels } from "../update-channels"; + +export interface SelectedUpdateChannel { + value: IComputedValue; + setValue: (channelId?: UpdateChannelId) => void; +} + +// export const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest"; + +// const updateChannel: PreferenceDescription = { +// fromStore(val) { +// return !val || !updateChannels.has(val) +// ? defaultUpdateChannel +// : val; +// }, +// toStore(val) { +// if (!updateChannels.has(val) || val === defaultUpdateChannel) { +// return undefined; +// } +// +// return val; +// }, +// }; + +const selectedUpdateChannelInjectable = getInjectable({ + id: "selected-update-channel", + + instantiate: (): SelectedUpdateChannel => { + const state = observable.box(updateChannels.latest); + + return { + value: computed(() => state.get()), + + setValue: action((channelId) => { + const targetUpdateChannel = channelId ? updateChannels[channelId] : updateChannels.latest; + + state.set(targetUpdateChannel); + }), + }; + }, +}); + +export default selectedUpdateChannelInjectable; diff --git a/src/main/update-app/update-channels.ts b/src/common/application-update/update-channels.ts similarity index 100% rename from src/main/update-app/update-channels.ts rename to src/common/application-update/update-channels.ts index 6720d8883f..c5f7b4b8c1 100644 --- a/src/main/update-app/update-channels.ts +++ b/src/common/application-update/update-channels.ts @@ -24,9 +24,9 @@ const alphaChannel: UpdateChannel = { }; export const updateChannels: Record = { - alpha: alphaChannel, - beta: betaChannel, latest: latestChannel, + beta: betaChannel, + alpha: alphaChannel, }; export interface UpdateChannel { diff --git a/src/main/update-app/check-for-platform-updates/check-for-platform-updates.injectable.ts b/src/main/update-app/check-for-platform-updates/check-for-platform-updates.injectable.ts index 6dffb1e670..edf36722c6 100644 --- a/src/main/update-app/check-for-platform-updates/check-for-platform-updates.injectable.ts +++ b/src/main/update-app/check-for-platform-updates/check-for-platform-updates.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import electronUpdaterInjectable from "../../electron-app/features/electron-updater.injectable"; -import type { UpdateChannel } from "../update-channels"; +import type { UpdateChannel } from "../../../common/application-update/update-channels"; import loggerInjectable from "../../../common/logger.injectable"; import type { UpdateCheckResult } from "electron-updater"; diff --git a/src/main/update-app/check-for-platform-updates/check-for-platform-updates.test.ts b/src/main/update-app/check-for-platform-updates/check-for-platform-updates.test.ts index 987361f915..b826a1a5a7 100644 --- a/src/main/update-app/check-for-platform-updates/check-for-platform-updates.test.ts +++ b/src/main/update-app/check-for-platform-updates/check-for-platform-updates.test.ts @@ -9,7 +9,7 @@ import asyncFn from "@async-fn/jest"; import type { AppUpdater, UpdateCheckResult } from "electron-updater"; import type { CheckForPlatformUpdates } from "./check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable"; -import type { UpdateChannel, UpdateChannelId } from "../update-channels"; +import type { UpdateChannel, UpdateChannelId } from "../../../common/application-update/update-channels"; import { getPromiseStatus } from "../../../common/test-utils/get-promise-status"; import loggerInjectable from "../../../common/logger.injectable"; import type { Logger } from "../../../common/logger"; diff --git a/src/main/update-app/check-for-updates/check-for-updates-starting-from-channel.injectable.ts b/src/main/update-app/check-for-updates/check-for-updates-starting-from-channel.injectable.ts index da27d8bcf2..dd13842036 100644 --- a/src/main/update-app/check-for-updates/check-for-updates-starting-from-channel.injectable.ts +++ b/src/main/update-app/check-for-updates/check-for-updates-starting-from-channel.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { UpdateChannel } from "../update-channels"; +import type { UpdateChannel } from "../../../common/application-update/update-channels"; import checkForPlatformUpdatesInjectable from "../check-for-platform-updates/check-for-platform-updates.injectable"; import updateCanBeDowngradedInjectable from "./update-can-be-downgraded.injectable"; diff --git a/src/main/update-app/check-for-updates/check-for-updates.injectable.ts b/src/main/update-app/check-for-updates/check-for-updates.injectable.ts index 5deb281e05..404e5aff72 100644 --- a/src/main/update-app/check-for-updates/check-for-updates.injectable.ts +++ b/src/main/update-app/check-for-updates/check-for-updates.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import selectedUpdateChannelInjectable from "../selected-update-channel.injectable"; +import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import updatesAreBeingDiscoveredInjectable from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable"; import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable"; import { runInAction } from "mobx"; diff --git a/src/main/update-app/check-for-updates/update-can-be-downgraded.injectable.ts b/src/main/update-app/check-for-updates/update-can-be-downgraded.injectable.ts index e1102e1026..72ea5c4023 100644 --- a/src/main/update-app/check-for-updates/update-can-be-downgraded.injectable.ts +++ b/src/main/update-app/check-for-updates/update-can-be-downgraded.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import selectedUpdateChannelInjectable from "../selected-update-channel.injectable"; +import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import appVersionInjectable from "../../../common/get-configuration-file-model/app-version/app-version.injectable"; import { SemVer } from "semver"; diff --git a/src/main/update-app/selected-update-channel.injectable.ts b/src/main/update-app/selected-update-channel.injectable.ts deleted file mode 100644 index a7b6a531c3..0000000000 --- a/src/main/update-app/selected-update-channel.injectable.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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 { IComputedValue } from "mobx"; -import { action, computed, observable } from "mobx"; -import type { UpdateChannel, UpdateChannelId } from "./update-channels"; -import { updateChannels } from "./update-channels"; - -export interface SelectedUpdateChannel { - value: IComputedValue; - setValue: (channelId: UpdateChannelId) => void; -} - -const selectedUpdateChannelInjectable = getInjectable({ - id: "selected-update-channel", - - instantiate: (): SelectedUpdateChannel => { - const state = observable.box(updateChannels.latest); - - return { - value: computed(() => state.get()), - - setValue: action((channelId: UpdateChannelId) => { - state.set(updateChannels[channelId]); - }), - }; - }, -}); - -export default selectedUpdateChannelInjectable; diff --git a/src/main/update-app/watch-if-update-should-happen-on-quit/watch-if-update-should-happen-on-quit.injectable.ts b/src/main/update-app/watch-if-update-should-happen-on-quit/watch-if-update-should-happen-on-quit.injectable.ts index 4996212490..12ec2d7c6e 100644 --- a/src/main/update-app/watch-if-update-should-happen-on-quit/watch-if-update-should-happen-on-quit.injectable.ts +++ b/src/main/update-app/watch-if-update-should-happen-on-quit/watch-if-update-should-happen-on-quit.injectable.ts @@ -6,8 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { autorun } from "mobx"; import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable"; import setUpdateOnQuitInjectable from "../../electron-app/features/set-update-on-quit.injectable"; -import selectedUpdateChannelInjectable from "../selected-update-channel.injectable"; -import type { UpdateChannel } from "../update-channels"; +import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable"; +import type { UpdateChannel } from "../../../common/application-update/update-channels"; import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable"; const watchIfUpdateShouldHappenOnQuitInjectable = getInjectable({