From c58f4151c96bab252aaece04b33d2c6a5c9725a0 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 21 Aug 2020 14:03:10 +0300 Subject: [PATCH] fix: don't repeat ipc-sync message to main renderer process/window when sending to frames Signed-off-by: Roman --- src/common/base-store.ts | 7 ++++++- src/common/ipc.ts | 7 +++++-- src/main/kube-auth-proxy.ts | 6 +----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/common/base-store.ts b/src/common/base-store.ts index 5013bffc72..146a81af36 100644 --- a/src/common/base-store.ts +++ b/src/common/base-store.ts @@ -132,7 +132,12 @@ export class BaseStore extends Singleton { broadcastIpc(msg); // send to all windows (BrowserWindow, webContents) const frames = await this.getSubFrames(); frames.forEach(frameId => { - broadcastIpc({ frameId, ...msg }); // send to all sub-frames (e.g. cluster-view managed in iframe) + // send to all sub-frames (e.g. cluster-view managed in iframe) + broadcastIpc({ + ...msg, + frameId: frameId, + frameOnly: true, + }); }); } diff --git a/src/common/ipc.ts b/src/common/ipc.ts index 8dfb2c45b2..b6b49aee51 100644 --- a/src/common/ipc.ts +++ b/src/common/ipc.ts @@ -54,12 +54,13 @@ export interface IpcBroadcastParams { channel: IpcChannel webContentId?: number; // send to single webContents view frameId?: number; // send to inner frame of webContents + frameOnly?: boolean; // send message only to view with provided `frameId` filter?: (webContent: WebContents) => boolean timeout?: number; // todo: add support args?: A; } -export function broadcastIpc({ channel, frameId, webContentId, filter, args = [] }: IpcBroadcastParams) { +export function broadcastIpc({ channel, frameId, frameOnly, webContentId, filter, args = [] }: IpcBroadcastParams) { const singleView = webContentId ? webContents.fromId(webContentId) : null; let views = singleView ? [singleView] : webContents.getAllWebContents(); if (filter) { @@ -68,7 +69,9 @@ export function broadcastIpc({ channel, frameId, webContentId, filter, args = [] views.forEach(webContent => { const type = webContent.getType(); logger.debug(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args }); - webContent.send(channel, ...args); + if (!frameOnly) { + webContent.send(channel, ...args); + } if (frameId) { webContent.sendToFrame(frameId, channel, ...args) } diff --git a/src/main/kube-auth-proxy.ts b/src/main/kube-auth-proxy.ts index 0db75a8a67..b388720cce 100644 --- a/src/main/kube-auth-proxy.ts +++ b/src/main/kube-auth-proxy.ts @@ -84,11 +84,7 @@ export class KubeAuthProxy { protected async sendIpcLogMessage(res: KubeAuthProxyLog) { const channel = `kube-auth:${this.cluster.id}` logger.info(`[KUBE-AUTH]: out-channel "${channel}"`, { ...res, meta: this.cluster.getMeta() }); - broadcastIpc({ - // webContentId: null, // todo: send a message only to single cluster's window - channel: channel, - args: [res], - }); + broadcastIpc({ channel: channel, args: [res] }); } public exit() {