1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-01-26 08:46:40 +02:00
parent 8a8ce3e692
commit 3e51d8d32a

View File

@ -17,14 +17,8 @@ export async function requestMain(channel: string, ...args: any[]) {
return ipcRenderer.invoke(channel, ...args); return ipcRenderer.invoke(channel, ...args);
} }
async function getSubFrames(processId: number): Promise<ClusterFrameInfo[]> { async function getSubFrames(): Promise<ClusterFrameInfo[]> {
const subFrames: ClusterFrameInfo[] = []; return Array.from(clusterFrameMap.values());
clusterFrameMap.forEach(frameInfo => {
subFrames.push(frameInfo);
});
return subFrames.filter(frame => frame.processId === processId);
} }
export async function broadcastMessage(channel: string, ...args: any[]) { export async function broadcastMessage(channel: string, ...args: any[]) {
@ -32,21 +26,25 @@ export async function broadcastMessage(channel: string, ...args: any[]) {
if (!views) return; if (!views) return;
let subFrames: Promise<ClusterFrameInfo[]>;
if (ipcRenderer) {
subFrames = requestMain(subFramesChannel);
} else {
subFrames = getSubFrames();
}
views.forEach(async webContent => { views.forEach(async webContent => {
const type = webContent.getType(); const type = webContent.getType();
logger.silly(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args }); logger.silly(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args });
webContent.send(channel, ...args); webContent.send(channel, ...args);
subFrames.then((frames) => {
let subFrames: ClusterFrameInfo[]; frames.map((frameInfo) => {
webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
if (ipcRenderer) { });
subFrames = await requestMain(subFramesChannel, webContent.getProcessId()); }).catch((e) => {
} else { logger.warning(`[IPC]: failed to broadcast ${channel} to frame`, { error: e});
subFrames = await getSubFrames(webContent.getProcessId());
}
subFrames.map((frameInfo) => {
webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
}); });
}); });
@ -84,7 +82,7 @@ export function unsubscribeAllFromBroadcast(channel: string) {
} }
export function bindBroadcastHandlers() { export function bindBroadcastHandlers() {
handleRequest(subFramesChannel, async (processId: number) => { handleRequest(subFramesChannel, async () => {
return toJS(await getSubFrames(processId), { recurseEverything: true }); return toJS(await getSubFrames(), { recurseEverything: true });
}); });
} }