mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move deactivating a cluster into injectable IPC (#7356)
* Move activating cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move deactivating a cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
497f63fde6
commit
ae9a8c3c41
16 files changed
+111
-96
No files matched your search
@@ -5,7 +5,6 @@
|
||||
|
||||
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
||||
export const clusterVisibilityHandler = "cluster:visibility";
|
||||
export const clusterDisconnectHandler = "cluster:disconnect";
|
||||
export const clusterStates = "cluster:states";
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,13 +9,12 @@
|
||||
|
||||
import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||
import { toJS } from "../utils/toJS";
|
||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
||||
import { clusterFrameMap } from "../cluster-frames";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
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";
|
||||
import clusterFramesInjectable from "../cluster-frames.injectable";
|
||||
|
||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||
|
||||
@@ -29,10 +28,6 @@ export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMai
|
||||
});
|
||||
}
|
||||
|
||||
function getSubFrames(): ClusterFrameInfo[] {
|
||||
return Array.from(clusterFrameMap.values());
|
||||
}
|
||||
|
||||
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
|
||||
if (ipcRenderer) {
|
||||
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
|
||||
@@ -44,12 +39,12 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
||||
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
|
||||
ipcMain.listeners(channel).forEach((func) => func({
|
||||
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
||||
}, ...args));
|
||||
|
||||
const subFrames = getSubFrames();
|
||||
const views = webContents.getAllWebContents();
|
||||
|
||||
if (!views || !Array.isArray(views) || views.length === 0) return;
|
||||
@@ -75,7 +70,7 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
||||
}
|
||||
|
||||
// Send message to subFrames of views.
|
||||
for (const frameInfo of subFrames) {
|
||||
for (const frameInfo of clusterFrames.values()) {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user