diff --git a/src/common/application-update/checking-for-updates/checking-for-updates-state.injectable.ts b/src/common/application-update/checking-for-updates/checking-for-updates-state.injectable.ts new file mode 100644 index 0000000000..dd21f471ce --- /dev/null +++ b/src/common/application-update/checking-for-updates/checking-for-updates-state.injectable.ts @@ -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; diff --git a/src/common/application-update/discovered-version/discovered-version-state.injectable.ts b/src/common/application-update/discovered-version/discovered-version-state.injectable.ts new file mode 100644 index 0000000000..f841c80c98 --- /dev/null +++ b/src/common/application-update/discovered-version/discovered-version-state.injectable.ts @@ -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; diff --git a/src/common/application-update/downloading-update/downloading-update-state.injectable.ts b/src/common/application-update/downloading-update/downloading-update-state.injectable.ts new file mode 100644 index 0000000000..d7f742d94c --- /dev/null +++ b/src/common/application-update/downloading-update/downloading-update-state.injectable.ts @@ -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; diff --git a/src/main/update-app/version-update.injectable.ts b/src/main/update-app/version-update.injectable.ts index 50f7a0a45f..527b64318b 100644 --- a/src/main/update-app/version-update.injectable.ts +++ b/src/main/update-app/version-update.injectable.ts @@ -3,14 +3,18 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { IComputedValue, IObservableValue } from "mobx"; -import { computed, observable, runInAction } from "mobx"; +import type { IComputedValue } from "mobx"; +import { computed, runInAction } from "mobx"; import selectedUpdateChannelInjectable from "./selected-update-channel.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 checkForPlatformUpdatesInjectable from "./check-for-platform-updates/check-for-platform-updates.injectable"; import type { UpdateChannel } from "./update-channels"; 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({ id: "version-update", @@ -20,30 +24,37 @@ const versionUpdateInjectable = getInjectable({ const downloadPlatformUpdate = di.inject(downloadPlatformUpdateInjectable); const checkForPlatformUpdates = di.inject(checkForPlatformUpdatesInjectable); const showNotification = di.inject(showNotificationInjectable); - - const discoveredVersionState = observable.box(); - const downloadingState = observable.box(false); - const checkingState = observable.box(false); - const discoveredFromUpdateChannelState = observable.box(); + const checkingForUpdatesState = di.inject(checkingForUpdatesStateInjectable); + const downloadingUpdateState = di.inject(downloadingUpdateStateInjectable); + const discoveredVersionState = di.inject(discoveredVersionStateInjectable); return { - discoveredVersion: computed(() => discoveredVersionState.get()), - discoveredFromUpdateChannel: computed(() => discoveredFromUpdateChannelState.get()), - downloading: computed(() => downloadingState.get()), - checking: computed(() => checkingState.get()), + discoveredVersion: computed(() => { + const discoveredVersion = discoveredVersionState.value.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( checkForPlatformUpdates, discoveredVersionState, - checkingState, selectedUpdateChannel.value, - discoveredFromUpdateChannelState, showNotification, + checkingForUpdatesState, ), downloadUpdate: downloadUpdateFor( downloadPlatformUpdate, - downloadingState, + downloadingUpdateState, ), }; }, @@ -53,33 +64,32 @@ export default versionUpdateInjectable; const downloadUpdateFor = ( - downloadPlatformUpdate: () => Promise, - downloadingState: IObservableValue, + downloadPlatformUpdate: () => Promise<{ downloadWasSuccessful: boolean }>, + downloadingUpdateState: SyncBox, ) => async () => { runInAction(() => { - downloadingState.set(true); + downloadingUpdateState.set(true); }); await downloadPlatformUpdate(); runInAction(() => { - downloadingState.set(false); + downloadingUpdateState.set(false); }); }; const checkForUpdatesFor = ( checkForPlatformUpdates: CheckForPlatformUpdates, - discoveredVersionState: IObservableValue, - checkingState: IObservableValue, + discoveredVersionState: SyncBox<{ version: string; updateChannel: UpdateChannel }>, selectedUpdateChannel: IComputedValue, - discoveredFromUpdateChannelState: IObservableValue, showNotification: (message: string) => void, + checkingForUpdatesState: SyncBox, ) => async () => { runInAction(() => { - checkingState.set(true); + checkingForUpdatesState.set(true); }); const checkForUpdatesStartingFromChannel = @@ -96,9 +106,8 @@ const checkForUpdatesFor = } runInAction(() => { - discoveredFromUpdateChannelState.set(actualUpdateChannel); - discoveredVersionState.set(version); - checkingState.set(false); + discoveredVersionState.set({ version, updateChannel: actualUpdateChannel }); + checkingForUpdatesState.set(false); }); return { updateWasDiscovered, version };