mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Change typing for after/before window/application start (#7342)
- 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> Signed-off-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
1 parent
351f57b3e9
commit
58fd010bc1
62 files changed
+185
-189
No files matched your search
+21
-20
@@ -8,33 +8,34 @@ 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: (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);
|
||||
})()
|
||||
};
|
||||
}
|
||||
),
|
||||
decorate: curry(decorator),
|
||||
target: startApplicationInjectionToken,
|
||||
}),
|
||||
|
||||
|
||||
Reference in new issue
Block a user