1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Extract states of application update to be usable from all environments

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-05-16 14:09:47 +03:00
parent 03f3d0933a
commit f2dc3112e7
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
4 changed files with 88 additions and 25 deletions

View File

@ -0,0 +1,18 @@
/**
* 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 createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable";
const checkingForUpdatesStateInjectable = getInjectable({
id: "checking-for-updates-state",
instantiate: (di) => {
const createSyncBox = di.inject(createSyncBoxInjectable);
return createSyncBox("checking-for-updates");
},
});
export default checkingForUpdatesStateInjectable;

View File

@ -0,0 +1,18 @@
/**
* 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 createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable";
const discoveredVersionStateInjectable = getInjectable({
id: "discovered-version-state",
instantiate: (di) => {
const createSyncBox = di.inject(createSyncBoxInjectable);
return createSyncBox("discovered-version-state");
},
});
export default discoveredVersionStateInjectable;

View File

@ -0,0 +1,18 @@
/**
* 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 createSyncBoxInjectable from "../../sync-box/create-sync-box.injectable";
const downloadingUpdateStateInjectable = getInjectable({
id: "downloading-update-state",
instantiate: (di) => {
const createSyncBox = di.inject(createSyncBoxInjectable);
return createSyncBox("downloading-update");
},
});
export default downloadingUpdateStateInjectable;

View File

@ -3,14 +3,18 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { IComputedValue, IObservableValue } from "mobx"; import type { IComputedValue } from "mobx";
import { computed, observable, runInAction } from "mobx"; import { computed, runInAction } from "mobx";
import selectedUpdateChannelInjectable from "./selected-update-channel.injectable"; import selectedUpdateChannelInjectable from "./selected-update-channel.injectable";
import downloadPlatformUpdateInjectable from "./download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "./download-platform-update/download-platform-update.injectable";
import type { CheckForPlatformUpdates } from "./check-for-platform-updates/check-for-platform-updates.injectable"; import type { CheckForPlatformUpdates } from "./check-for-platform-updates/check-for-platform-updates.injectable";
import checkForPlatformUpdatesInjectable from "./check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./check-for-platform-updates/check-for-platform-updates.injectable";
import type { UpdateChannel } from "./update-channels"; import type { UpdateChannel } from "./update-channels";
import showNotificationInjectable from "../show-notification/show-notification.injectable"; import showNotificationInjectable from "../show-notification/show-notification.injectable";
import checkingForUpdatesStateInjectable from "../../common/application-update/checking-for-updates/checking-for-updates-state.injectable";
import type { SyncBox } from "../../common/sync-box/create-sync-box.injectable";
import downloadingUpdateStateInjectable from "../../common/application-update/downloading-update/downloading-update-state.injectable";
import discoveredVersionStateInjectable from "../../common/application-update/discovered-version/discovered-version-state.injectable";
const versionUpdateInjectable = getInjectable({ const versionUpdateInjectable = getInjectable({
id: "version-update", id: "version-update",
@ -20,30 +24,37 @@ const versionUpdateInjectable = getInjectable({
const downloadPlatformUpdate = di.inject(downloadPlatformUpdateInjectable); const downloadPlatformUpdate = di.inject(downloadPlatformUpdateInjectable);
const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable); const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable);
const showNotification = di.inject(showNotificationInjectable); const showNotification = di.inject(showNotificationInjectable);
const checkingForUpdatesState = di.inject(checkingForUpdatesStateInjectable);
const discoveredVersionState = observable.box<string>(); const downloadingUpdateState = di.inject(downloadingUpdateStateInjectable);
const downloadingState = observable.box<boolean>(false); const discoveredVersionState = di.inject(discoveredVersionStateInjectable);
const checkingState = observable.box<boolean>(false);
const discoveredFromUpdateChannelState = observable.box<UpdateChannel>();
return { return {
discoveredVersion: computed(() => discoveredVersionState.get()), discoveredVersion: computed(() => {
discoveredFromUpdateChannel: computed(() => discoveredFromUpdateChannelState.get()), const discoveredVersion = discoveredVersionState.value.get();
downloading: computed(() => downloadingState.get()),
checking: computed(() => checkingState.get()), return discoveredVersion?.version;
}),
discoveredFromUpdateChannel: computed(() => {
const discoveredVersion = discoveredVersionState.value.get();
return discoveredVersion?.updateChannel;
}),
downloading: computed(() => downloadingUpdateState.value.get()),
checking: computed(() => checkingForUpdatesState.value.get()),
checkForUpdates: checkForUpdatesFor( checkForUpdates: checkForUpdatesFor(
checkForPlatformUpdates, checkForPlatformUpdates,
discoveredVersionState, discoveredVersionState,
checkingState,
selectedUpdateChannel.value, selectedUpdateChannel.value,
discoveredFromUpdateChannelState,
showNotification, showNotification,
checkingForUpdatesState,
), ),
downloadUpdate: downloadUpdateFor( downloadUpdate: downloadUpdateFor(
downloadPlatformUpdate, downloadPlatformUpdate,
downloadingState, downloadingUpdateState,
), ),
}; };
}, },
@ -53,33 +64,32 @@ export default versionUpdateInjectable;
const downloadUpdateFor = const downloadUpdateFor =
( (
downloadPlatformUpdate: () => Promise<void>, downloadPlatformUpdate: () => Promise<{ downloadWasSuccessful: boolean }>,
downloadingState: IObservableValue<boolean>, downloadingUpdateState: SyncBox<boolean>,
) => ) =>
async () => { async () => {
runInAction(() => { runInAction(() => {
downloadingState.set(true); downloadingUpdateState.set(true);
}); });
await downloadPlatformUpdate(); await downloadPlatformUpdate();
runInAction(() => { runInAction(() => {
downloadingState.set(false); downloadingUpdateState.set(false);
}); });
}; };
const checkForUpdatesFor = const checkForUpdatesFor =
( (
checkForPlatformUpdates: CheckForPlatformUpdates, checkForPlatformUpdates: CheckForPlatformUpdates,
discoveredVersionState: IObservableValue<string>, discoveredVersionState: SyncBox<{ version: string; updateChannel: UpdateChannel }>,
checkingState: IObservableValue<boolean>,
selectedUpdateChannel: IComputedValue<UpdateChannel>, selectedUpdateChannel: IComputedValue<UpdateChannel>,
discoveredFromUpdateChannelState: IObservableValue<UpdateChannel>,
showNotification: (message: string) => void, showNotification: (message: string) => void,
checkingForUpdatesState: SyncBox<boolean>,
) => ) =>
async () => { async () => {
runInAction(() => { runInAction(() => {
checkingState.set(true); checkingForUpdatesState.set(true);
}); });
const checkForUpdatesStartingFromChannel = const checkForUpdatesStartingFromChannel =
@ -96,9 +106,8 @@ const checkForUpdatesFor =
} }
runInAction(() => { runInAction(() => {
discoveredFromUpdateChannelState.set(actualUpdateChannel); discoveredVersionState.set({ version, updateChannel: actualUpdateChannel });
discoveredVersionState.set(version); checkingForUpdatesState.set(false);
checkingState.set(false);
}); });
return { updateWasDiscovered, version }; return { updateWasDiscovered, version };