mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix ipc broadcast to frames from renderer
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
f38b307d9e
commit
3f158f4a4b
@ -3,6 +3,7 @@
|
|||||||
// https://www.electronjs.org/docs/api/ipc-renderer
|
// https://www.electronjs.org/docs/api/ipc-renderer
|
||||||
|
|
||||||
import { ipcMain, ipcRenderer, webContents, remote } from "electron";
|
import { ipcMain, ipcRenderer, webContents, remote } from "electron";
|
||||||
|
import { toJS } from "mobx";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { ClusterFrameInfo, clusterFrameMap } from "./cluster-frames";
|
import { ClusterFrameInfo, clusterFrameMap } from "./cluster-frames";
|
||||||
|
|
||||||
@ -24,8 +25,15 @@ async function getSubFrames(): Promise<ClusterFrameInfo[]> {
|
|||||||
return subFrames;
|
return subFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function broadcastMessage(channel: string, ...args: any[]) {
|
export async function broadcastMessage(channel: string, ...args: any[]) {
|
||||||
const views = (webContents || remote?.webContents)?.getAllWebContents();
|
let subFrames: ClusterFrameInfo[];
|
||||||
|
|
||||||
|
if (ipcRenderer) {
|
||||||
|
subFrames = await requestMain("ipc:get-sub-frames");
|
||||||
|
} else {
|
||||||
|
subFrames = await getSubFrames();
|
||||||
|
}
|
||||||
|
const views = (webContents || remote.webContents)?.getAllWebContents();
|
||||||
|
|
||||||
if (!views) return;
|
if (!views) return;
|
||||||
|
|
||||||
@ -34,11 +42,9 @@ export function broadcastMessage(channel: string, ...args: any[]) {
|
|||||||
|
|
||||||
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);
|
||||||
getSubFrames().then((frames) => {
|
subFrames.map((frameInfo) => {
|
||||||
frames.map((frameInfo) => {
|
webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
||||||
webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
});
|
||||||
});
|
|
||||||
}).catch((e) => e);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
@ -73,3 +79,9 @@ export function unsubscribeAllFromBroadcast(channel: string) {
|
|||||||
ipcMain.removeAllListeners(channel);
|
ipcMain.removeAllListeners(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function bindBroadcastHandlers() {
|
||||||
|
handleRequest("ipc:get-sub-frames", async () => {
|
||||||
|
return toJS(await getSubFrames(), { recurseEverything: true });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user