mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Now the callback is provided with an object containing either `mainDi` or `windowDi` fields. This should help with confusion over which environment the `di` is for Signed-off-by: Sebastian Malton <sebastian@malton.name>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import {
|
|
DiContainer,
|
|
getInjectable,
|
|
instantiationDecoratorToken,
|
|
lifecycleEnum,
|
|
} from "@ogre-tools/injectable";
|
|
import { startApplicationInjectionToken } from "@k8slens/application";
|
|
import whenAppIsReadyInjectable from "./when-app-is-ready.injectable";
|
|
import { beforeAnythingInjectionToken, beforeElectronIsReadyInjectionToken } from "./time-slots";
|
|
import { runManySyncFor } from "@k8slens/run-many";
|
|
import { curry } from "lodash";
|
|
|
|
type ToBeDecorated = (di: DiContainer, ...args: unknown[]) => (...args: unknown[]) => unknown;
|
|
|
|
const decorator = (toBeDecorated: unknown, di: DiContainer, ...args: unknown[]) => {
|
|
const whenAppIsReady = di.inject(whenAppIsReadyInjectable);
|
|
const runManySync = runManySyncFor(di);
|
|
const beforeAnything = runManySync(beforeAnythingInjectionToken);
|
|
const beforeElectronIsReady = runManySync(beforeElectronIsReadyInjectionToken);
|
|
const startApplication = (toBeDecorated as ToBeDecorated)(di, ...args);
|
|
|
|
return (...startApplicationArgs: unknown[]) => {
|
|
beforeAnything();
|
|
beforeElectronIsReady();
|
|
|
|
return (async () => {
|
|
await whenAppIsReady();
|
|
|
|
return startApplication(...startApplicationArgs);
|
|
})();
|
|
};
|
|
};
|
|
|
|
const startElectronApplicationInjectable = getInjectable({
|
|
id: "start-electron-application",
|
|
|
|
instantiate: () => ({
|
|
decorate: curry(decorator),
|
|
target: startApplicationInjectionToken,
|
|
}),
|
|
|
|
decorable: false,
|
|
|
|
injectionToken: instantiationDecoratorToken,
|
|
|
|
lifecycle: lifecycleEnum.singleton,
|
|
});
|
|
|
|
export default startElectronApplicationInjectable;
|