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:
1 parent
cd4fda5495
commit
e3579d82cb
3 files changed
+122
-58
No files matched your search
@@ -5,24 +5,32 @@
|
||||
|
||||
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> = {
|
||||
alpha: {
|
||||
id: "alpha",
|
||||
label: "Alpha",
|
||||
},
|
||||
|
||||
beta: {
|
||||
id: "beta",
|
||||
label: "Beta",
|
||||
},
|
||||
|
||||
latest: {
|
||||
id: "latest",
|
||||
label: "Stable",
|
||||
},
|
||||
alpha: alphaChannel,
|
||||
beta: betaChannel,
|
||||
latest: latestChannel,
|
||||
};
|
||||
|
||||
export interface UpdateChannel {
|
||||
readonly id: UpdateChannelId;
|
||||
readonly label: string;
|
||||
readonly moreStableUpdateChannel: UpdateChannel | null;
|
||||
}
|
||||
@@ -62,26 +62,48 @@ const downloadUpdateFor =
|
||||
});
|
||||
};
|
||||
|
||||
const checkForUpdatesFor = (
|
||||
checkForPlatformUpdates: CheckForPlatformUpdates,
|
||||
discoveredVersionState: IObservableValue<string>,
|
||||
checkingState: IObservableValue<boolean>,
|
||||
selectedUpdateChannel: IComputedValue<UpdateChannel>,
|
||||
) => {
|
||||
return async () => {
|
||||
runInAction(() => {
|
||||
checkingState.set(true);
|
||||
});
|
||||
const checkForUpdatesFor =
|
||||
(
|
||||
checkForPlatformUpdates: CheckForPlatformUpdates,
|
||||
discoveredVersionState: IObservableValue<string>,
|
||||
checkingState: IObservableValue<boolean>,
|
||||
selectedUpdateChannel: IComputedValue<UpdateChannel>,
|
||||
) =>
|
||||
async () => {
|
||||
runInAction(() => {
|
||||
checkingState.set(true);
|
||||
});
|
||||
|
||||
const { updateWasDiscovered, version } = await checkForPlatformUpdates(
|
||||
selectedUpdateChannel.get(),
|
||||
);
|
||||
const checkForUpdatesStartingFromChannel =
|
||||
checkForUpdatesStartingFromChannelFor(checkForPlatformUpdates);
|
||||
|
||||
runInAction(() => {
|
||||
discoveredVersionState.set(version);
|
||||
checkingState.set(false);
|
||||
});
|
||||
const { updateWasDiscovered, version } = await checkForUpdatesStartingFromChannel(
|
||||
selectedUpdateChannel.get(),
|
||||
);
|
||||
|
||||
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;
|
||||
};
|
||||
Reference in new issue
Block a user