mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
95 lines
3.8 KiB
TypeScript
95 lines
3.8 KiB
TypeScript
/**
|
|
* 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 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";
|
|
import assert from "assert";
|
|
import askBooleanInjectable from "../../ask-boolean/ask-boolean.injectable";
|
|
import quitAndInstallUpdateInjectable from "../../electron-app/features/quit-and-install-update.injectable";
|
|
import downloadUpdateInjectable from "../download-update/download-update.injectable";
|
|
import broadcastChangeInUpdatingStatusInjectable from "./broadcast-change-in-updating-status.injectable";
|
|
import checkForUpdatesStartingFromChannelInjectable from "./check-for-updates-starting-from-channel.injectable";
|
|
|
|
const processCheckingForUpdatesInjectable = getInjectable({
|
|
id: "process-checking-for-updates",
|
|
|
|
instantiate: (di) => {
|
|
const askBoolean = di.inject(askBooleanInjectable);
|
|
const quitAndInstallUpdate = di.inject(quitAndInstallUpdateInjectable);
|
|
const downloadUpdate = di.inject(downloadUpdateInjectable);
|
|
const selectedUpdateChannel = di.inject(selectedUpdateChannelInjectable);
|
|
const broadcastChangeInUpdatingStatus = di.inject(broadcastChangeInUpdatingStatusInjectable);
|
|
const checkingForUpdatesState = di.inject(updatesAreBeingDiscoveredInjectable);
|
|
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
|
const checkForUpdatesStartingFromChannel = di.inject(checkForUpdatesStartingFromChannelInjectable);
|
|
|
|
return async () => {
|
|
broadcastChangeInUpdatingStatus({ eventId: "checking-for-updates" });
|
|
|
|
runInAction(() => {
|
|
checkingForUpdatesState.set(true);
|
|
});
|
|
|
|
const { updateWasDiscovered, version, actualUpdateChannel } =
|
|
await checkForUpdatesStartingFromChannel(selectedUpdateChannel.value.get());
|
|
|
|
if (!updateWasDiscovered) {
|
|
broadcastChangeInUpdatingStatus({ eventId: "no-updates-available" });
|
|
|
|
runInAction(() => {
|
|
discoveredVersionState.set(null);
|
|
checkingForUpdatesState.set(false);
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
broadcastChangeInUpdatingStatus({
|
|
eventId: "download-for-update-started",
|
|
version,
|
|
});
|
|
|
|
runInAction(() => {
|
|
// TODO: Unacceptable damage caused by strict mode
|
|
assert(version);
|
|
assert(actualUpdateChannel);
|
|
|
|
discoveredVersionState.set({
|
|
version,
|
|
updateChannel: actualUpdateChannel,
|
|
});
|
|
|
|
checkingForUpdatesState.set(false);
|
|
});
|
|
|
|
// Note: intentional orphan promise to make download happen in the background
|
|
downloadUpdate().then(async ({ downloadWasSuccessful }) => {
|
|
if (!downloadWasSuccessful) {
|
|
broadcastChangeInUpdatingStatus({
|
|
eventId: "download-for-update-failed",
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
const userWantsToInstallUpdate = await askBoolean({
|
|
title: "Update Available",
|
|
|
|
question: `Version ${version} of Lens IDE is available and ready to be installed. Would you like to update now?\n\n` +
|
|
`Lens should restart automatically, if it doesn't please restart manually. Installed extensions might require updating.`,
|
|
});
|
|
|
|
if (userWantsToInstallUpdate) {
|
|
quitAndInstallUpdate();
|
|
}
|
|
});
|
|
};
|
|
},
|
|
});
|
|
|
|
export default processCheckingForUpdatesInjectable;
|