mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Implement checking of updates from multiple update channels
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
cd4fda5495
commit
e3579d82cb
@ -12,10 +12,12 @@ import type { CheckForPlatformUpdates } from "../../main/update-app/check-for-pl
|
|||||||
import checkForPlatformUpdatesInjectable from "../../main/update-app/check-for-platform-updates.injectable";
|
import checkForPlatformUpdatesInjectable from "../../main/update-app/check-for-platform-updates.injectable";
|
||||||
import type { AsyncFnMock } from "@async-fn/jest";
|
import type { AsyncFnMock } from "@async-fn/jest";
|
||||||
import asyncFn 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 { updateChannels } from "../../main/update-app/update-channels";
|
||||||
import downloadPlatformUpdateInjectable from "../../main/update-app/download-platform-update.injectable";
|
import downloadPlatformUpdateInjectable from "../../main/update-app/download-platform-update.injectable";
|
||||||
import selectedUpdateChannelInjectable from "../../main/update-app/selected-update-channel.injectable";
|
import selectedUpdateChannelInjectable from "../../main/update-app/selected-update-channel.injectable";
|
||||||
import progressOfUpdateDownloadInjectable from "../../main/update-app/progress-of-update-download.injectable";
|
import progressOfUpdateDownloadInjectable from "../../main/update-app/progress-of-update-download.injectable";
|
||||||
|
import type { IComputedValue } from "mobx";
|
||||||
|
|
||||||
describe("installing update using tray", () => {
|
describe("installing update using tray", () => {
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
@ -70,7 +72,8 @@ describe("installing update using tray", () => {
|
|||||||
let checkForUpdatesPromise: Promise<void>;
|
let checkForUpdatesPromise: Promise<void>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
checkForUpdatesPromise = applicationBuilder.tray.click("check-for-updates");
|
checkForUpdatesPromise =
|
||||||
|
applicationBuilder.tray.click("check-for-updates");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks for updates from "latest" update channel', () => {
|
it('checks for updates from "latest" update channel', () => {
|
||||||
@ -166,7 +169,9 @@ describe("installing update using tray", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("when download progresses, percentage increases", () => {
|
it("when download progresses, percentage increases", () => {
|
||||||
const progressOfUpdateDownload = applicationBuilder.dis.mainDi.inject(progressOfUpdateDownloadInjectable);
|
const progressOfUpdateDownload = applicationBuilder.dis.mainDi.inject(
|
||||||
|
progressOfUpdateDownloadInjectable,
|
||||||
|
);
|
||||||
|
|
||||||
progressOfUpdateDownload.setValue(42);
|
progressOfUpdateDownload.setValue(42);
|
||||||
|
|
||||||
@ -231,24 +236,19 @@ describe("installing update using tray", () => {
|
|||||||
|
|
||||||
describe("when user changes update channel to other channel instead of just installing", () => {
|
describe("when user changes update channel to other channel instead of just installing", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const selectedUpdateChannel = applicationBuilder.dis.mainDi.inject(selectedUpdateChannelInjectable);
|
const selectedUpdateChannel = applicationBuilder.dis.mainDi.inject(
|
||||||
|
selectedUpdateChannelInjectable,
|
||||||
|
);
|
||||||
|
|
||||||
selectedUpdateChannel.setValue(updateChannels.beta.id);
|
selectedUpdateChannel.setValue(updateChannels.beta.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("user cannot install existing update for being from wrong update channel", () => {
|
it("user cannot install existing update for being from wrong update channel", () => {});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when user installs an update", () => {
|
describe("when user installs an update", () => {
|
||||||
|
beforeEach(() => {});
|
||||||
|
|
||||||
beforeEach(() => {
|
it('still installs the update from "latest" update channel', () => {});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('still installs the update from "latest" update channel', () => {
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when checking updates again, checks for updates from the other update channel", async () => {
|
it("when checking updates again, checks for updates from the other update channel", async () => {
|
||||||
@ -265,42 +265,75 @@ describe("installing update using tray", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('given update channel "alpha" is selected, when checking for updates', () => {
|
describe('given update channel "alpha" is selected, when checking for updates', () => {
|
||||||
beforeEach(() => {
|
let selectedUpdateChannel: {
|
||||||
|
value: IComputedValue<UpdateChannel>;
|
||||||
|
setValue: (channelId: UpdateChannelId) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
selectedUpdateChannel = applicationBuilder.dis.mainDi.inject(
|
||||||
|
selectedUpdateChannelInjectable,
|
||||||
|
);
|
||||||
|
|
||||||
|
selectedUpdateChannel.setValue(updateChannels.alpha.id);
|
||||||
|
|
||||||
|
applicationBuilder.tray.click("check-for-updates");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks updates from update channel "alpha"', () => {
|
it('checks updates from update channel "alpha"', () => {
|
||||||
|
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
|
||||||
|
updateChannels.alpha,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when update is discovered, does not check update from other update channels", () => {
|
it("when update is discovered, does not check update from other update channels", async () => {
|
||||||
|
checkForPlatformUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
await checkForPlatformUpdatesMock.resolve({ updateWasDiscovered: true });
|
||||||
|
|
||||||
|
expect(checkForPlatformUpdatesMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when no update is discovered", () => {
|
describe("when no update is discovered", () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
|
checkForPlatformUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
await checkForPlatformUpdatesMock.resolve({ updateWasDiscovered: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('checks updates from update channel "beta"', () => {
|
it('checks updates from update channel "beta"', () => {
|
||||||
|
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
|
||||||
|
updateChannels.beta,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when update is discovered, does not check update from other update channels", () => {
|
it("when update is discovered, does not check update from other update channels", async () => {
|
||||||
|
checkForPlatformUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
await checkForPlatformUpdatesMock.resolve({ updateWasDiscovered: true });
|
||||||
|
|
||||||
|
expect(checkForPlatformUpdatesMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when no update is discovered again", () => {
|
describe("when no update is discovered again", () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
|
checkForPlatformUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
await checkForPlatformUpdatesMock.resolve({ updateWasDiscovered: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('finally checks updates from update channel "latest"', () => {
|
it('finally checks updates from update channel "latest"', () => {
|
||||||
|
expect(checkForPlatformUpdatesMock).toHaveBeenCalledWith(
|
||||||
|
updateChannels.latest,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when update is discovered, does not check update from other update channels", () => {
|
it("when update is discovered, does not check update from other update channels", async () => {
|
||||||
|
checkForPlatformUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
await checkForPlatformUpdatesMock.resolve({ updateWasDiscovered: true });
|
||||||
|
|
||||||
|
expect(checkForPlatformUpdatesMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -321,9 +354,9 @@ describe("installing update using tray", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("user can install the update", () => {
|
it("user can install the update", () => {
|
||||||
expect(
|
expect(applicationBuilder.tray.get("install-update").label.get()).toBe(
|
||||||
applicationBuilder.tray.get("install-update").label.get(),
|
'Install update "some-old-version"',
|
||||||
).toBe('Install update "some-old-version"');
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders", () => {
|
it("renders", () => {
|
||||||
@ -344,7 +377,8 @@ describe("installing update using tray", () => {
|
|||||||
let checkForUpdatesPromise: Promise<void>;
|
let checkForUpdatesPromise: Promise<void>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
checkForUpdatesPromise = applicationBuilder.tray.click("check-for-updates");
|
checkForUpdatesPromise =
|
||||||
|
applicationBuilder.tray.click("check-for-updates");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("user cannot check for updates again", () => {
|
it("user cannot check for updates again", () => {
|
||||||
|
|||||||
@ -5,24 +5,32 @@
|
|||||||
|
|
||||||
export type UpdateChannelId = "alpha" | "beta" | "latest";
|
export type UpdateChannelId = "alpha" | "beta" | "latest";
|
||||||
|
|
||||||
|
const latestChannel: UpdateChannel = {
|
||||||
|
id: "latest",
|
||||||
|
label: "Stable",
|
||||||
|
moreStableUpdateChannel: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const betaChannel: UpdateChannel = {
|
||||||
|
id: "beta",
|
||||||
|
label: "Beta",
|
||||||
|
moreStableUpdateChannel: latestChannel,
|
||||||
|
};
|
||||||
|
|
||||||
|
const alphaChannel: UpdateChannel = {
|
||||||
|
id: "alpha",
|
||||||
|
label: "Alpha",
|
||||||
|
moreStableUpdateChannel: betaChannel,
|
||||||
|
};
|
||||||
|
|
||||||
export const updateChannels: Record<UpdateChannelId, UpdateChannel> = {
|
export const updateChannels: Record<UpdateChannelId, UpdateChannel> = {
|
||||||
alpha: {
|
alpha: alphaChannel,
|
||||||
id: "alpha",
|
beta: betaChannel,
|
||||||
label: "Alpha",
|
latest: latestChannel,
|
||||||
},
|
|
||||||
|
|
||||||
beta: {
|
|
||||||
id: "beta",
|
|
||||||
label: "Beta",
|
|
||||||
},
|
|
||||||
|
|
||||||
latest: {
|
|
||||||
id: "latest",
|
|
||||||
label: "Stable",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface UpdateChannel {
|
export interface UpdateChannel {
|
||||||
readonly id: UpdateChannelId;
|
readonly id: UpdateChannelId;
|
||||||
readonly label: string;
|
readonly label: string;
|
||||||
|
readonly moreStableUpdateChannel: UpdateChannel | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,26 +62,48 @@ const downloadUpdateFor =
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkForUpdatesFor = (
|
const checkForUpdatesFor =
|
||||||
checkForPlatformUpdates: CheckForPlatformUpdates,
|
(
|
||||||
discoveredVersionState: IObservableValue<string>,
|
checkForPlatformUpdates: CheckForPlatformUpdates,
|
||||||
checkingState: IObservableValue<boolean>,
|
discoveredVersionState: IObservableValue<string>,
|
||||||
selectedUpdateChannel: IComputedValue<UpdateChannel>,
|
checkingState: IObservableValue<boolean>,
|
||||||
) => {
|
selectedUpdateChannel: IComputedValue<UpdateChannel>,
|
||||||
return async () => {
|
) =>
|
||||||
runInAction(() => {
|
async () => {
|
||||||
checkingState.set(true);
|
runInAction(() => {
|
||||||
});
|
checkingState.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
const { updateWasDiscovered, version } = await checkForPlatformUpdates(
|
const checkForUpdatesStartingFromChannel =
|
||||||
selectedUpdateChannel.get(),
|
checkForUpdatesStartingFromChannelFor(checkForPlatformUpdates);
|
||||||
);
|
|
||||||
|
|
||||||
runInAction(() => {
|
const { updateWasDiscovered, version } = await checkForUpdatesStartingFromChannel(
|
||||||
discoveredVersionState.set(version);
|
selectedUpdateChannel.get(),
|
||||||
checkingState.set(false);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
return { updateWasDiscovered };
|
runInAction(() => {
|
||||||
|
discoveredVersionState.set(version);
|
||||||
|
checkingState.set(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return { updateWasDiscovered };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const checkForUpdatesStartingFromChannelFor = (checkForPlatformUpdates: CheckForPlatformUpdates) => {
|
||||||
|
const _recursiveCheck = async (updateChannel: UpdateChannel): Promise<{ updateWasDiscovered: boolean; version?: string }> => {
|
||||||
|
const result = await checkForPlatformUpdates(updateChannel);
|
||||||
|
|
||||||
|
if (result.updateWasDiscovered) {
|
||||||
|
return { updateWasDiscovered: true, version: result.version };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateChannel.moreStableUpdateChannel) {
|
||||||
|
return await _recursiveCheck(updateChannel.moreStableUpdateChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { updateWasDiscovered: false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return _recursiveCheck;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user