mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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:
parent
e32d9a9e7a
commit
eb8d316eea
@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`installing update from update channels when started renders 1`] = `
|
||||
exports[`installing update from update channels given no update channel selection is stored, when started renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
@ -10,7 +10,7 @@ exports[`installing update from update channels when started renders 1`] = `
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`installing update from update channels when started when user checks for updates renders 1`] = `
|
||||
exports[`installing update from update channels given no update channel selection is stored, when started when user checks for updates renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
@ -20,7 +20,7 @@ exports[`installing update from update channels when started when user checks fo
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`installing update from update channels when started when user checks for updates when new update is discovered renders 1`] = `
|
||||
exports[`installing update from update channels given no update channel selection is stored, when started when user checks for updates when new update is discovered renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
@ -30,7 +30,7 @@ exports[`installing update from update channels when started when user checks fo
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`installing update from update channels when started when user checks for updates when new update is discovered when download succeeds renders 1`] = `
|
||||
exports[`installing update from update channels given no update channel selection is stored, when started when user checks for updates when new update is discovered when download succeeds renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
|
||||
@ -23,6 +23,8 @@ import type { AskBoolean } from "../../main/ask-boolean/ask-boolean.injectable";
|
||||
import askBooleanInjectable from "../../main/ask-boolean/ask-boolean.injectable";
|
||||
import showInfoNotificationInjectable from "../../renderer/components/notifications/show-info-notification.injectable";
|
||||
import checkForUpdatesInjectable from "../../main/update-app/check-for-updates/check-for-updates.injectable";
|
||||
import appVersionInjectable
|
||||
from "../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
|
||||
describe("installing update from update channels", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
@ -69,7 +71,7 @@ describe("installing update from update channels", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when started", () => {
|
||||
describe("given no update channel selection is stored, when started", () => {
|
||||
let rendered: RenderResult;
|
||||
let checkForUpdates: () => Promise<void>;
|
||||
|
||||
@ -299,4 +301,88 @@ describe("installing update from update channels", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("given valid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
// TODO: Switch to more natural way of setting initial value
|
||||
// TODO: UserStore is currently responsible for getting and setting initial value
|
||||
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
|
||||
|
||||
selectedUpdateChannel.setValue(updateChannels.beta.id);
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
|
||||
const checkForUpdates = applicationBuilder.dis.mainDi.inject(checkForUpdatesInjectable);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
|
||||
});
|
||||
|
||||
it("given invalid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
// TODO: Switch to more natural way of setting initial value
|
||||
// TODO: UserStore is currently responsible for getting and setting initial value
|
||||
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
|
||||
|
||||
selectedUpdateChannel.setValue("something-invalid" as UpdateChannelId);
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
|
||||
const checkForUpdates = applicationBuilder.dis.mainDi.inject(checkForUpdatesInjectable);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.latest, expect.any(Object));
|
||||
});
|
||||
|
||||
it('given no update channel selection is stored and currently using alpha release, when checking for updates, checks for updates from "alpha" channel', async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
mainDi.override(appVersionInjectable, () => "1.0.0-alpha");
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
|
||||
const checkForUpdates = applicationBuilder.dis.mainDi.inject(checkForUpdatesInjectable);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.alpha, expect.any(Object));
|
||||
});
|
||||
|
||||
it('given no update channel selection is stored and currently using beta release, when checking for updates, checks for updates from "beta" channel', async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
mainDi.override(appVersionInjectable, () => "1.0.0-beta");
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
|
||||
const checkForUpdates = applicationBuilder.dis.mainDi.inject(checkForUpdatesInjectable);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
|
||||
});
|
||||
|
||||
it("given update channel selection is stored and currently using prerelease, when checking for updates, checks for updates from stored channel", async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||
mainDi.override(appVersionInjectable, () => "1.0.0-alpha");
|
||||
|
||||
// TODO: Switch to more natural way of setting initial value
|
||||
// TODO: UserStore is currently responsible for getting and setting initial value
|
||||
const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable);
|
||||
|
||||
selectedUpdateChannel.setValue(updateChannels.beta.id);
|
||||
});
|
||||
|
||||
await applicationBuilder.render();
|
||||
|
||||
const checkForUpdates = applicationBuilder.dis.mainDi.inject(checkForUpdatesInjectable);
|
||||
|
||||
checkForUpdates();
|
||||
|
||||
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(updateChannels.beta, expect.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user