diff --git a/src/common/cluster/current-cluster-channel.ts b/src/common/cluster/current-cluster-channel.ts new file mode 100644 index 0000000000..957baa6f9c --- /dev/null +++ b/src/common/cluster/current-cluster-channel.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import type { ClusterId } from "../cluster-types"; +import type { MessageChannel } from "../utils/channel/message-channel-listener-injection-token"; + +export const currentClusterMessageChannel: MessageChannel = { + id: "current-visible-cluster", +}; diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index 32c21d0bf2..58bb386810 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -40,7 +40,6 @@ import clusterFramesInjectable from "../common/cluster-frames.injectable"; import type { ClusterFrameInfo } from "../common/cluster-frames"; import { observable, runInAction } from "mobx"; import waitForElectronToBeReadyInjectable from "./electron-app/features/wait-for-electron-to-be-ready.injectable"; -import setupListenerForCurrentClusterFrameInjectable from "./start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable"; import setupRunnablesAfterWindowIsOpenedInjectable from "./electron-app/runnables/setup-runnables-after-window-is-opened.injectable"; import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable"; import getElectronThemeInjectable from "./electron-app/features/get-electron-theme.injectable"; @@ -178,7 +177,6 @@ const overrideRunnablesHavingSideEffects = (di: DiContainer) => { setupShellInjectable, setupSyncingOfWeblinksInjectable, setupSystemCaInjectable, - setupListenerForCurrentClusterFrameInjectable, setupRunnablesAfterWindowIsOpenedInjectable, startCatalogSyncInjectable, startKubeConfigSyncInjectable, diff --git a/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts b/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts new file mode 100644 index 0000000000..d29210cda1 --- /dev/null +++ b/src/main/start-main-application/lens-window/current-cluster-frame/listener.injectable.ts @@ -0,0 +1,19 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { currentClusterMessageChannel } from "../../../../common/cluster/current-cluster-channel"; +import { getMessageChannelListenerInjectable } from "../../../../common/utils/channel/message-channel-listener-injection-token"; +import currentClusterFrameClusterIdStateInjectable from "./current-cluster-frame-cluster-id-state.injectable"; + +const currentVisibileClusterListenerInjectable = getMessageChannelListenerInjectable({ + id: "current-visibile-cluster", + channel: currentClusterMessageChannel, + handler: (di) => { + const currentClusterFrameState = di.inject(currentClusterFrameClusterIdStateInjectable); + + return clusterId => currentClusterFrameState.set(clusterId); + }, +}); + +export default currentVisibileClusterListenerInjectable; diff --git a/src/main/start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable.ts b/src/main/start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable.ts deleted file mode 100644 index 24554c474f..0000000000 --- a/src/main/start-main-application/lens-window/current-cluster-frame/setup-listener-for-current-cluster-frame.injectable.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ -import { ipcMainOn } from "../../../../common/ipc"; -import { IpcRendererNavigationEvents } from "../../../../renderer/navigation/events"; -import type { ClusterId } from "../../../../common/cluster-types"; - -import { getInjectable } from "@ogre-tools/injectable"; -import { onLoadOfApplicationInjectionToken } from "../../runnable-tokens/on-load-of-application-injection-token"; -import currentClusterFrameClusterIdStateInjectable from "./current-cluster-frame-cluster-id-state.injectable"; - -const setupListenerForCurrentClusterFrameInjectable = getInjectable({ - id: "setup-listener-for-current-cluster-frame", - - instantiate: (di) => ({ - id: "setup-listener-for-current-cluster-frame", - run: () => { - const currentClusterFrameState = di.inject(currentClusterFrameClusterIdStateInjectable); - - ipcMainOn( - IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, - (event, clusterId: ClusterId) => { - currentClusterFrameState.set(clusterId); - }, - ); - }, - }), - - causesSideEffects: true, - - injectionToken: onLoadOfApplicationInjectionToken, -}); - -export default setupListenerForCurrentClusterFrameInjectable;