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>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-13 15:35:33 +02:00
1 parent b99b06980e
commit a63f737adb
62 files changed
+185 -189

No files matched your search

@@ -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,
}),
@@ -7,7 +7,7 @@ import {
} from "@k8slens/application";
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
import whenAppIsReadyInjectable from "./start-application/when-app-is-ready.injectable";
import { beforeAnythingInjectionToken, beforeElectronIsReadyInjectionToken } from "./start-application/time-slots";
import * as timeSlots from "./start-application/time-slots";
describe("starting-of-electron-main-application", () => {
let di: DiContainer;
@@ -30,13 +30,13 @@ describe("starting-of-electron-main-application", () => {
const beforeAnythingIsLoadingInjectable = getInjectable({
id: "before-anything",
instantiate: () => ({ run: beforeAnythingMock }),
injectionToken: beforeAnythingInjectionToken,
injectionToken: timeSlots.beforeAnythingInjectionToken,
});
const beforeElectronIsReadyIsLoadingInjectable = getInjectable({
id: "before-electron-is-ready",
instantiate: () => ({ run: beforeElectronIsReadyMock }),
injectionToken: beforeElectronIsReadyInjectionToken,
injectionToken: timeSlots.beforeElectronIsReadyInjectionToken,
});
const beforeApplicationIsLoadingInjectable = getInjectable({