1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/technical-features/application/electron-main/src/start-application/start-electron-application.injectable.ts
Sebastian Malton a1f651c287
Use new @k8slens/run-many package in core
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-03-10 09:39:22 +02:00

49 lines
1.6 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";
type ToBeDecorated = (di: DiContainer, ...args: unknown[]) => (...args: unknown[]) => unknown;
const startElectronApplicationInjectable = getInjectable({
id: "start-electron-application",
instantiate: () => ({
decorate: (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);
})()
};
}
),
target: startApplicationInjectionToken,
}),
decorable: false,
injectionToken: instantiationDecoratorToken,
lifecycle: lifecycleEnum.singleton,
});
export default startElectronApplicationInjectable;