From 1da282444ae09eb65a65c1c87289cfd05080f88d Mon Sep 17 00:00:00 2001 From: Jari Kolehmainen Date: Fri, 29 Jan 2021 11:40:25 +0200 Subject: [PATCH] ipc fix Signed-off-by: Jari Kolehmainen --- src/common/ipc.ts | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/common/ipc.ts b/src/common/ipc.ts index 8368cdde6b..d4bd1da7c5 100644 --- a/src/common/ipc.ts +++ b/src/common/ipc.ts @@ -17,7 +17,7 @@ export async function requestMain(channel: string, ...args: any[]) { return ipcRenderer.invoke(channel, ...args); } -async function getSubFrames(): Promise { +function getSubFrames(): ClusterFrameInfo[] { return Array.from(clusterFrameMap.values()); } @@ -26,29 +26,30 @@ export async function broadcastMessage(channel: string, ...args: any[]) { if (!views) return; - const subFrames: Promise = ipcRenderer - ? requestMain(subFramesChannel) - : getSubFrames(); - - views.forEach(async webContent => { - const type = webContent.getType(); - - logger.silly(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args }); - webContent.send(channel, ...args); - subFrames.then((frames) => { - frames.map((frameInfo) => { - webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args); - }); - }).catch((e) => { - logger.warning(`[IPC]: failed to broadcast ${channel} to frame`, { error: e}); - }); - }); - if (ipcRenderer) { ipcRenderer.send(channel, ...args); } else { ipcMain.emit(channel, ...args); } + + for (const view of views) { + const type = view.getType(); + + logger.silly(`[IPC]: broadcasting "${channel}" to ${type}=${view.id}`, { args }); + view.send(channel, ...args); + + try { + const subFrames: ClusterFrameInfo[] = ipcRenderer + ? await requestMain(subFramesChannel) + : getSubFrames(); + + for (const frameInfo of subFrames) { + view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args); + } + } catch (error) { + logger.error("[IPC]: failed to send IPC message", { error }); + } + } } export function subscribeToBroadcast(channel: string, listener: (...args: any[]) => any) {