Update injectable library (#4842)

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
This commit is contained in:
Janne SavolainenandMikko Aspiala authored and GitHub committed 2022-02-25 11:10:13 -05:00
1 parent e8ca1ddf87
commit b65f6e00ec
231 files changed
+630 -613

No files matched your search

@@ -2,12 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import electronAppInjectable from "../get-electron-app-path/electron-app/electron-app.injectable";
const appNameInjectable = getInjectable({
id: "app-name",
instantiate: (di) => di.inject(electronAppInjectable).name,
lifecycle: lifecycleEnum.singleton,
});
export default appNameInjectable;
+18 -17
View File
@@ -3,9 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import {
DependencyInjectionContainer,
DiContainerForSetup,
getInjectable,
lifecycleEnum,
} from "@ogre-tools/injectable";
import {
@@ -22,38 +21,40 @@ import appNameInjectable from "./app-name/app-name.injectable";
import directoryForIntegrationTestingInjectable from "./directory-for-integration-testing/directory-for-integration-testing.injectable";
const appPathsInjectable = getInjectable({
setup: (di) => {
const directoryForIntegrationTesting = di.inject(
id: "app-paths",
setup: async (di) => {
const directoryForIntegrationTesting = await di.inject(
directoryForIntegrationTestingInjectable,
);
if (directoryForIntegrationTesting) {
setupPathForAppDataInIntegrationTesting(di, directoryForIntegrationTesting);
await setupPathForAppDataInIntegrationTesting(di, directoryForIntegrationTesting);
}
setupPathForUserData(di);
registerAppPathsChannel(di);
await setupPathForUserData(di);
await registerAppPathsChannel(di);
},
instantiate: (di) =>
getAppPaths({ getAppPath: di.inject(getElectronAppPathInjectable) }),
injectionToken: appPathsInjectionToken,
lifecycle: lifecycleEnum.singleton,
});
export default appPathsInjectable;
const registerAppPathsChannel = (di: DependencyInjectionContainer) => {
const registerChannel = di.inject(registerChannelInjectable);
const registerAppPathsChannel = async (di: DiContainerForSetup) => {
const registerChannel = await di.inject(registerChannelInjectable);
const appPaths = await di.inject(appPathsInjectable);
registerChannel(appPathsIpcChannel, () => di.inject(appPathsInjectable));
registerChannel(appPathsIpcChannel, () => appPaths);
};
const setupPathForUserData = (di: DependencyInjectionContainer) => {
const setElectronAppPath = di.inject(setElectronAppPathInjectable);
const appName = di.inject(appNameInjectable);
const getAppPath = di.inject(getElectronAppPathInjectable);
const setupPathForUserData = async (di: DiContainerForSetup) => {
const setElectronAppPath = await di.inject(setElectronAppPathInjectable);
const appName = await di.inject(appNameInjectable);
const getAppPath = await di.inject(getElectronAppPathInjectable);
const appDataPath = getAppPath("appData");
@@ -61,8 +62,8 @@ const setupPathForUserData = (di: DependencyInjectionContainer) => {
};
// Todo: this kludge is here only until we have a proper place to setup integration testing.
const setupPathForAppDataInIntegrationTesting = (di: DependencyInjectionContainer, appDataPath: string) => {
const setElectronAppPath = di.inject(setElectronAppPathInjectable);
const setupPathForAppDataInIntegrationTesting = async (di: DiContainerForSetup, appDataPath: string) => {
const setElectronAppPath = await di.inject(setElectronAppPathInjectable);
setElectronAppPath("appData", appDataPath);
};
@@ -2,11 +2,11 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
const directoryForIntegrationTestingInjectable = getInjectable({
id: "directory-for-integration-testing",
instantiate: () => process.env.CICD,
lifecycle: lifecycleEnum.singleton,
});
export default directoryForIntegrationTestingInjectable;
@@ -2,12 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import { app } from "electron";
const electronAppInjectable = getInjectable({
id: "electron-app",
instantiate: () => app,
lifecycle: lifecycleEnum.singleton,
causesSideEffects: true,
});
@@ -2,15 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import electronAppInjectable from "./electron-app/electron-app.injectable";
import { getElectronAppPath } from "./get-electron-app-path";
const getElectronAppPathInjectable = getInjectable({
id: "get-electron-app-path",
instantiate: (di) =>
getElectronAppPath({ app: di.inject(electronAppInjectable) }),
lifecycle: lifecycleEnum.singleton,
});
export default getElectronAppPathInjectable;
@@ -2,12 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import { ipcMain } from "electron";
const ipcMainInjectable = getInjectable({
id: "ipc-main",
instantiate: () => ipcMain,
lifecycle: lifecycleEnum.singleton,
causesSideEffects: true,
});
@@ -2,16 +2,16 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import ipcMainInjectable from "./ipc-main/ipc-main.injectable";
import { registerChannel } from "./register-channel";
const registerChannelInjectable = getInjectable({
id: "register-channel",
instantiate: (di) => registerChannel({
ipcMain: di.inject(ipcMainInjectable),
}),
lifecycle: lifecycleEnum.singleton,
});
export default registerChannelInjectable;
@@ -2,15 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { PathName } from "../../../common/app-paths/app-path-names";
import electronAppInjectable from "../get-electron-app-path/electron-app/electron-app.injectable";
const setElectronAppPathInjectable = getInjectable({
id: "set-electron-app-path",
instantiate: (di) => (name: PathName, path: string) : void =>
di.inject(electronAppInjectable).setPath(name, path),
lifecycle: lifecycleEnum.singleton,
});
export default setElectronAppPathInjectable;