From 0d3728dba3d321c51983c48eb40af517c780a653 Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Wed, 27 Apr 2022 11:10:12 +0300 Subject: [PATCH] Consolidate setup events to more granular timeslots Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- src/common/setupable-injection-token/run-setups.ts | 13 ++++++++++--- src/main/app-paths/setup-app-paths.injectable.ts | 9 +++++---- .../app-paths/setup-app-paths.injectable.ts | 6 +++--- .../register-ipc-channel-listeners.injectable.ts | 6 +++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/common/setupable-injection-token/run-setups.ts b/src/common/setupable-injection-token/run-setups.ts index af76c05b3b..b6ecbac9cf 100644 --- a/src/common/setupable-injection-token/run-setups.ts +++ b/src/common/setupable-injection-token/run-setups.ts @@ -3,12 +3,19 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { DiContainer } from "@ogre-tools/injectable"; -import { setupableInjectionToken } from "./setupable-injection-token"; +import { beforeApplicationIsReadyInjectionToken } from "../../main/start-main-application/before-application-is-ready/before-application-is-ready-injection-token"; +import { onApplicationIsReadyInjectionToken } from "../../main/start-main-application/on-application-is-ready/on-application-is-ready-injection-token"; export const runSetups = async (di: DiContainer) => { await Promise.all( di - .injectMany(setupableInjectionToken) - .map((setupable) => setupable.runSetup()), + .injectMany(beforeApplicationIsReadyInjectionToken) + .map((setupable) => setupable.run()), + ); + + await Promise.all( + di + .injectMany(onApplicationIsReadyInjectionToken) + .map((setupable) => setupable.run()), ); }; diff --git a/src/main/app-paths/setup-app-paths.injectable.ts b/src/main/app-paths/setup-app-paths.injectable.ts index 6a6e976e7e..fc4e3d28ae 100644 --- a/src/main/app-paths/setup-app-paths.injectable.ts +++ b/src/main/app-paths/setup-app-paths.injectable.ts @@ -3,13 +3,11 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; - import type { AppPaths } from "../../common/app-paths/app-path-injection-token"; import getElectronAppPathInjectable from "./get-electron-app-path/get-electron-app-path.injectable"; import setElectronAppPathInjectable from "./set-electron-app-path/set-electron-app-path.injectable"; import appNameInjectable from "./app-name/app-name.injectable"; import directoryForIntegrationTestingInjectable from "./directory-for-integration-testing/directory-for-integration-testing.injectable"; -import { setupableInjectionToken } from "../../common/setupable-injection-token/setupable-injection-token"; import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable"; import { pathNames } from "../../common/app-paths/app-path-names"; import { fromPairs, map } from "lodash/fp"; @@ -17,6 +15,9 @@ import { pipeline } from "@ogre-tools/fp"; import { appPathsIpcChannel } from "../../common/app-paths/app-path-injection-token"; import registerChannelInjectable from "./register-channel/register-channel.injectable"; import joinPathsInjectable from "../../common/path/join-paths.injectable"; +import { + beforeApplicationIsReadyInjectionToken, +} from "../start-main-application/before-application-is-ready/before-application-is-ready-injection-token"; const setupAppPathsInjectable = getInjectable({ id: "setup-app-paths", @@ -31,7 +32,7 @@ const setupAppPathsInjectable = getInjectable({ const joinPaths = di.inject(joinPathsInjectable); return { - runSetup: () => { + run: () => { if (directoryForIntegrationTesting) { setElectronAppPath("appData", directoryForIntegrationTesting); } @@ -53,7 +54,7 @@ const setupAppPathsInjectable = getInjectable({ }; }, - injectionToken: setupableInjectionToken, + injectionToken: beforeApplicationIsReadyInjectionToken, }); export default setupAppPathsInjectable; diff --git a/src/renderer/app-paths/setup-app-paths.injectable.ts b/src/renderer/app-paths/setup-app-paths.injectable.ts index ab0303083f..8581aba206 100644 --- a/src/renderer/app-paths/setup-app-paths.injectable.ts +++ b/src/renderer/app-paths/setup-app-paths.injectable.ts @@ -5,8 +5,8 @@ import { getInjectable } from "@ogre-tools/injectable"; import { AppPaths, appPathsIpcChannel } from "../../common/app-paths/app-path-injection-token"; import getValueFromRegisteredChannelInjectable from "./get-value-from-registered-channel/get-value-from-registered-channel.injectable"; -import { setupableInjectionToken } from "../../common/setupable-injection-token/setupable-injection-token"; import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable"; +import { onApplicationIsReadyInjectionToken } from "../../main/start-main-application/on-application-is-ready/on-application-is-ready-injection-token"; let syncAppPaths: AppPaths; @@ -14,7 +14,7 @@ const setupAppPathsInjectable = getInjectable({ id: "setup-app-paths", instantiate: (di) => ({ - runSetup: async () => { + run: async () => { const getValueFromRegisteredChannel = di.inject( getValueFromRegisteredChannelInjectable, ); @@ -27,7 +27,7 @@ const setupAppPathsInjectable = getInjectable({ }, }), - injectionToken: setupableInjectionToken, + injectionToken: onApplicationIsReadyInjectionToken, }); export default setupAppPathsInjectable; diff --git a/src/renderer/ipc-channel-listeners/register-ipc-channel-listeners.injectable.ts b/src/renderer/ipc-channel-listeners/register-ipc-channel-listeners.injectable.ts index 097f2f70e3..c18d9e20fe 100644 --- a/src/renderer/ipc-channel-listeners/register-ipc-channel-listeners.injectable.ts +++ b/src/renderer/ipc-channel-listeners/register-ipc-channel-listeners.injectable.ts @@ -5,13 +5,13 @@ import { getInjectable } from "@ogre-tools/injectable"; import { ipcChannelListenerInjectionToken } from "./ipc-channel-listener-injection-token"; import registerIpcChannelListenerInjectable from "../app-paths/get-value-from-registered-channel/register-ipc-channel-listener.injectable"; -import { setupableInjectionToken } from "../../common/setupable-injection-token/setupable-injection-token"; +import { onApplicationIsReadyInjectionToken } from "../../main/start-main-application/on-application-is-ready/on-application-is-ready-injection-token"; const registerIpcChannelListenersInjectable = getInjectable({ id: "register-ipc-channel-listeners", instantiate: di => ({ - runSetup: async () => { + run: async () => { const registerIpcChannelListener = di.inject(registerIpcChannelListenerInjectable); const listeners = di.injectMany(ipcChannelListenerInjectionToken); @@ -22,7 +22,7 @@ const registerIpcChannelListenersInjectable = getInjectable({ }, }), - injectionToken: setupableInjectionToken, + injectionToken: onApplicationIsReadyInjectionToken, }); export default registerIpcChannelListenersInjectable;