diff --git a/src/common/ipc/ipc-main-injection-token.ts b/src/common/ipc/ipc-main-injection-token.ts new file mode 100644 index 000000000000..932c700c97a0 --- /dev/null +++ b/src/common/ipc/ipc-main-injection-token.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectionToken } from "@ogre-tools/injectable"; +import type { IpcMain } from "electron"; + +const ipcMainInjectionToken = getInjectionToken({ + id: "ipc-main-injection-token", +}); + +export default ipcMainInjectionToken; diff --git a/src/common/ipc/ipc.ts b/src/common/ipc/ipc.ts index f11227d17e26..e84fcfec5645 100644 --- a/src/common/ipc/ipc.ts +++ b/src/common/ipc/ipc.ts @@ -12,17 +12,17 @@ import { toJS } from "../utils/toJS"; import type { ClusterFrameInfo } from "../cluster-frames"; import { clusterFrameMap } from "../cluster-frames"; import type { Disposer } from "../utils"; -import ipcMainInjectable from "../../main/utils/channel/ipc-main/ipc-main.injectable"; import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable"; import loggerInjectable from "../logger.injectable"; +import ipcMainInjectionToken from "./ipc-main-injection-token"; export const broadcastMainChannel = "ipc:broadcast-main"; export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) { const di = getLegacyGlobalDiForExtensionApi(); - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); ipcMain.handle(channel, async (event, ...args) => { return sanitizePayload(await listener(event, ...args)); @@ -90,7 +90,7 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer { const di = getLegacyGlobalDiForExtensionApi(); - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); ipcMain.on(channel, listener); diff --git a/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts b/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts index 6be9826c989d..bdcd3034d38c 100644 --- a/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts +++ b/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts @@ -4,11 +4,11 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { reaction } from "mobx"; +import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token"; import { catalogInitChannel } from "../../common/ipc/catalog"; import { disposer, toJS } from "../../common/utils"; import { getStartableStoppable } from "../../common/utils/get-startable-stoppable"; import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable"; -import ipcMainInjectable from "../utils/channel/ipc-main/ipc-main.injectable"; import catalogSyncBroadcasterInjectable from "./broadcaster.injectable"; const catalogSyncToRendererInjectable = getInjectable({ @@ -16,7 +16,7 @@ const catalogSyncToRendererInjectable = getInjectable({ instantiate: (di) => { const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); const catalogSyncBroadcaster = di.inject(catalogSyncBroadcasterInjectable); return getStartableStoppable( diff --git a/src/main/start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable.ts b/src/main/start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable.ts index 2c0f30b83b62..4046db5d9daa 100644 --- a/src/main/start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable.ts +++ b/src/main/start-main-application/lens-window/application-window/wait-until-bundled-extensions-are-loaded.injectable.ts @@ -3,15 +3,15 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token"; import { bundledExtensionsLoaded } from "../../../../common/ipc/extension-handling"; import { delay } from "../../../../common/utils"; -import ipcMainInjectable from "../../../utils/channel/ipc-main/ipc-main.injectable"; const waitUntilBundledExtensionsAreLoadedInjectable = getInjectable({ id: "wait-until-bundled-extensions-are-loaded", instantiate: (di) => { - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); return async () => { const viewHasLoaded = new Promise((resolve) => { diff --git a/src/main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable.ts b/src/main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable.ts index 6ace54c8454d..db6435ea56a0 100644 --- a/src/main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable.ts +++ b/src/main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable.ts @@ -4,14 +4,14 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { IpcMainEvent } from "electron"; -import ipcMainInjectable from "../ipc-main/ipc-main.injectable"; import { enlistMessageChannelListenerInjectionToken } from "../../../../common/utils/channel/enlist-message-channel-listener-injection-token"; +import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token"; const enlistMessageChannelListenerInjectable = getInjectable({ id: "enlist-message-channel-listener-for-main", instantiate: (di) => { - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); return ({ channel, handler }) => { const nativeOnCallback = (_: IpcMainEvent, message: unknown) => { diff --git a/src/main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable.ts b/src/main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable.ts index d72e4afcaf56..1af1b6fb551d 100644 --- a/src/main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable.ts +++ b/src/main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable.ts @@ -4,10 +4,10 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import type { IpcMainInvokeEvent } from "electron"; -import ipcMainInjectable from "../ipc-main/ipc-main.injectable"; import type { Disposer } from "../../../../common/utils"; import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token"; import type { RequestChannelListener } from "./listener-tokens"; +import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token"; export type EnlistRequestChannelListener = >(listener: RequestChannelListener) => Disposer; @@ -15,7 +15,7 @@ const enlistRequestChannelListenerInjectable = getInjectable({ id: "enlist-request-channel-listener-for-main", instantiate: (di): EnlistRequestChannelListener => { - const ipcMain = di.inject(ipcMainInjectable); + const ipcMain = di.inject(ipcMainInjectionToken); return ({ channel, handler }) => { const nativeHandleCallback = (_: IpcMainInvokeEvent, request: unknown) => handler(request); diff --git a/src/main/utils/channel/ipc-main/ipc-main.injectable.ts b/src/main/utils/channel/ipc-main/ipc-main.injectable.ts index 13684bf8eca1..b012c5be475f 100644 --- a/src/main/utils/channel/ipc-main/ipc-main.injectable.ts +++ b/src/main/utils/channel/ipc-main/ipc-main.injectable.ts @@ -4,11 +4,13 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { ipcMain } from "electron"; +import ipcMainInjectionToken from "../../../../common/ipc/ipc-main-injection-token"; const ipcMainInjectable = getInjectable({ id: "ipc-main", instantiate: () => ipcMain, causesSideEffects: true, + injectionToken: ipcMainInjectionToken, }); export default ipcMainInjectable;