Switch to using competition to setup app paths

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

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-05-11 08:18:32 +03:00
1 parent b8fd1299ee
commit 3782b36809
7 files changed
+142 -100

No files matched your search

@@ -1,28 +0,0 @@
/**
* 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 type { AppPaths } from "../../common/app-paths/app-path-injection-token";
import { appPathsInjectionToken, appPathsIpcChannel } from "../../common/app-paths/app-path-injection-token";
import getValueFromRegisteredChannelInjectable from "./get-value-from-registered-channel/get-value-from-registered-channel.injectable";
let syncAppPaths: AppPaths;
const appPathsInjectable = getInjectable({
id: "app-paths",
setup: async (di) => {
const getValueFromRegisteredChannel = await di.inject(
getValueFromRegisteredChannelInjectable,
);
syncAppPaths = await getValueFromRegisteredChannel(appPathsIpcChannel);
},
instantiate: () => syncAppPaths,
injectionToken: appPathsInjectionToken,
});
export default appPathsInjectable;
@@ -0,0 +1,33 @@
/**
* 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 { AppPaths, appPathsIpcChannel } from "../../common/app-paths/app-path-injection-token";
import getValueFromRegisteredChannelInjectable from "./get-value-from-registered-channel/get-value-from-registered-channel.injectable";
import { setupableInjectionToken } from "../../common/setupable-injection-token/setupable-injection-token";
import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable";
let syncAppPaths: AppPaths;
const setupAppPathsInjectable = getInjectable({
id: "setup-app-paths",
instantiate: (di) => ({
doSetup: async () => {
const getValueFromRegisteredChannel = di.inject(
getValueFromRegisteredChannelInjectable,
);
syncAppPaths = await getValueFromRegisteredChannel(appPathsIpcChannel);
const appPathsState = di.inject(appPathsStateInjectable);
appPathsState.set(syncAppPaths);
},
}),
injectionToken: setupableInjectionToken,
});
export default setupAppPathsInjectable;