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

46 lines
1.9 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { runManyFor, runManySyncFor } from "@k8slens/run-many";
import * as phases from "./runnable-tokens/phases";
import waitForElectronToBeReadyInjectable from "../electron-app/features/wait-for-electron-to-be-ready.injectable";
const startMainApplicationInjectable = getInjectable({
id: "start-main-application",
instantiate: (di) => {
const runMany = runManyFor(di);
const runManySync = runManySyncFor(di);
const waitForElectronToBeReady = di.inject(waitForElectronToBeReadyInjectable);
const appPathsRunnablePhase = runManySync(phases.appPathsRunnablePhaseInjectionToken);
const beforeElectronIsReady = runManySync(phases.beforeElectronIsReadyInjectionToken);
const beforeApplicationIsLoading = runMany(phases.beforeApplicationIsLoadingInjectionToken);
const showLoadingRunnablePhase = runMany(phases.showLoadingRunnablePhaseInjectionToken);
const onLoadOfApplication = runMany(phases.onLoadOfApplicationInjectionToken);
const showInitialWindowRunnablePhase = runMany(phases.showInitialWindowRunnablePhaseInjectionToken);
const afterApplicationIsLoaded = runMany(phases.afterApplicationIsLoadedInjectionToken);
return () => {
// Stuff happening before application is ready needs to be synchronous because of
// https://github.com/electron/electron/issues/21370
appPathsRunnablePhase();
beforeElectronIsReady();
return (async () => {
await waitForElectronToBeReady();
await beforeApplicationIsLoading();
await showLoadingRunnablePhase();
await onLoadOfApplication();
await showInitialWindowRunnablePhase();
await afterApplicationIsLoaded();
})();
};
},
});
export default startMainApplicationInjectable;