1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/utils/sync-box/provide-initial-values-for-sync-boxes.injectable.ts
Janne Savolainen af4b74d9bd
Open application only if new update is available when using tray to check for updates (#5948)
* Prevent opening of application if no new updates were downloaded when checking for updates using tray when application window is closed

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix getting initial value of sync box

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Tweak naming of variable

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-07-29 15:55:16 +03:00

48 lines
1.9 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 { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
import syncBoxInitialValueChannelInjectable from "../../../common/utils/sync-box/sync-box-initial-value-channel.injectable";
import createSyncBoxStateInjectable from "../../../common/utils/sync-box/sync-box-state.injectable";
import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token";
import { runInAction } from "mobx";
import type { SyncBox } from "../../../common/utils/sync-box/sync-box-injection-token";
import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token";
import assert from "assert";
const provideInitialValuesForSyncBoxesInjectable = getInjectable({
id: "provide-initial-values-for-sync-boxes",
instantiate: (di) => {
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
const syncBoxInitialValueChannel = di.inject(syncBoxInitialValueChannelInjectable);
const syncBoxes = di.injectMany(syncBoxInjectionToken);
const setSyncBoxState = (syncBox: SyncBox<any>, state: any) =>
di.inject(createSyncBoxStateInjectable, syncBox.id).set(state);
return {
run: async () => {
const initialValues = await requestFromChannel(syncBoxInitialValueChannel);
runInAction(() => {
initialValues.forEach(({ id, value }) => {
const syncBox = syncBoxes.find((box) => box.id === id);
assert(syncBox);
setSyncBoxState(syncBox, value);
});
});
},
};
},
injectionToken: beforeFrameStartsInjectionToken,
});
export default provideInitialValuesForSyncBoxesInjectable;