Fix Electron 9.4 frame ipc bug (#1888)

* use pid+frameId

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* use correct process id

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2021-01-04 14:16:35 +02:00
1 parent 8c70e055ee
commit 06d41acc26
5 files changed
+30 -20

No files matched your search

+6 -1
View File
@@ -1,3 +1,8 @@
import { observable } from "mobx";
export const clusterFrameMap = observable.map<string, number>();
export type ClusterFrameInfo = {
frameId: number;
processId: number
};
export const clusterFrameMap = observable.map<string, ClusterFrameInfo>();
+3 -3
View File
@@ -2,7 +2,7 @@ import { handleRequest } from "./ipc";
import { ClusterId, clusterStore } from "./cluster-store";
import { appEventBus } from "./event-bus";
import { ResourceApplier } from "../main/resource-applier";
import { ipcMain } from "electron";
import { ipcMain, IpcMainInvokeEvent } from "electron";
import { clusterFrameMap } from "./cluster-frames";
export const clusterActivateHandler = "cluster:activate";
@@ -21,11 +21,11 @@ if (ipcMain) {
}
});
handleRequest(clusterSetFrameIdHandler, (event, clusterId: ClusterId, frameId: number) => {
handleRequest(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
const cluster = clusterStore.getById(clusterId);
if (cluster) {
clusterFrameMap.set(cluster.id, frameId);
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
return cluster.pushState();
}
+7 -7
View File
@@ -4,7 +4,7 @@
import { ipcMain, ipcRenderer, webContents, remote } from "electron";
import logger from "../main/logger";
import { clusterFrameMap } from "./cluster-frames";
import { ClusterFrameInfo, clusterFrameMap } from "./cluster-frames";
export function handleRequest(channel: string, listener: (...args: any[]) => any) {
ipcMain.handle(channel, listener);
@@ -14,11 +14,11 @@ export async function requestMain(channel: string, ...args: any[]) {
return ipcRenderer.invoke(channel, ...args);
}
async function getSubFrames(): Promise<number[]> {
const subFrames: number[] = [];
async function getSubFrames(): Promise<ClusterFrameInfo[]> {
const subFrames: ClusterFrameInfo[] = [];
clusterFrameMap.forEach(frameId => {
subFrames.push(frameId);
clusterFrameMap.forEach(frameInfo => {
subFrames.push(frameInfo);
});
return subFrames;
@@ -35,8 +35,8 @@ export function broadcastMessage(channel: string, ...args: any[]) {
logger.silly(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args });
webContent.send(channel, ...args);
getSubFrames().then((frames) => {
frames.map((frameId) => {
webContent.sendToFrame(frameId, channel, ...args);
frames.map((frameInfo) => {
webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
});
}).catch((e) => e);
});