Switch to using release channel of installed application version as default value for selected update channel

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen committed 2022-06-03 07:48:05 +03:00
1 parent c12b7dc7ae
commit 09a5cfe3bd
4 files changed
+126 -25

No files matched your search

@@ -0,0 +1,27 @@
/**
* 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 { SemVer } from "semver";
import appVersionInjectable from "../../get-configuration-file-model/app-version/app-version.injectable";
import type { UpdateChannelId } from "../update-channels";
import { updateChannels } from "../update-channels";
const defaultUpdateChannelInjectable = getInjectable({
id: "default-update-channel",
instantiate: (di) => {
const appVersion = di.inject(appVersionInjectable);
const currentReleaseChannel = new SemVer(appVersion).prerelease[0]?.toString() as UpdateChannelId;
if (currentReleaseChannel && updateChannels[currentReleaseChannel]) {
return updateChannels[currentReleaseChannel];
}
return updateChannels.latest;
},
});
export default defaultUpdateChannelInjectable;
@@ -7,40 +7,28 @@ import type { IComputedValue } from "mobx";
import { action, computed, observable } from "mobx";
import type { UpdateChannel, UpdateChannelId } from "../update-channels";
import { updateChannels } from "../update-channels";
import defaultUpdateChannelInjectable from "./default-update-channel.injectable";
export interface SelectedUpdateChannel {
value: IComputedValue<UpdateChannel>;
setValue: (channelId?: UpdateChannelId) => void;
}
// export const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
// const updateChannel: PreferenceDescription<string> = {
// 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);
instantiate: (di): SelectedUpdateChannel => {
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
const state = observable.box(defaultUpdateChannel);
return {
value: computed(() => state.get()),
setValue: action((channelId) => {
const targetUpdateChannel = channelId ? updateChannels[channelId] : updateChannels.latest;
const targetUpdateChannel =
channelId && updateChannels[channelId]
? updateChannels[channelId]
: defaultUpdateChannel;
state.set(targetUpdateChannel);
}),