1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

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 2021-01-04 14:16:35 +02:00 committed by GitHub
parent 8c70e055ee
commit 06d41acc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 20 deletions

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>();

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();
}

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);
});

View File

@ -7,7 +7,7 @@ import { subscribeToBroadcast } from "../common/ipc";
import { initMenu } from "./menu";
import { initTray } from "./tray";
import { Singleton } from "../common/utils";
import { clusterFrameMap } from "../common/cluster-frames";
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
export class WindowManager extends Singleton {
protected mainWindow: BrowserWindow;
@ -118,9 +118,9 @@ export class WindowManager extends Singleton {
return this.mainWindow;
}
sendToView({ channel, frameId, data = [] }: { channel: string, frameId?: number, data?: any[] }) {
if (frameId) {
this.mainWindow.webContents.sendToFrame(frameId, channel, ...data);
sendToView({ channel, frameInfo, data = [] }: { channel: string, frameInfo?: ClusterFrameInfo, data?: any[] }) {
if (frameInfo) {
this.mainWindow.webContents.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...data);
} else {
this.mainWindow.webContents.send(channel, ...data);
}
@ -128,18 +128,23 @@ export class WindowManager extends Singleton {
async navigate(url: string, frameId?: number) {
await this.ensureMainWindow();
let frameInfo: ClusterFrameInfo;
if (frameId) {
frameInfo = Array.from(clusterFrameMap.values()).find((frameInfo) => frameInfo.frameId === frameId);
}
this.sendToView({
channel: "renderer:navigate",
frameId,
frameInfo,
data: [url],
});
}
reload() {
const frameId = clusterFrameMap.get(this.activeClusterId);
const frameInfo = clusterFrameMap.get(this.activeClusterId);
if (frameId) {
this.sendToView({ channel: "renderer:reload", frameId });
if (frameInfo) {
this.sendToView({ channel: "renderer:reload", frameInfo });
} else {
webContents.getFocusedWebContents()?.reload();
}

View File

@ -57,7 +57,7 @@ export class App extends React.Component {
logger.info(`[APP]: Init dashboard, clusterId=${clusterId}, frameId=${frameId}`);
await Terminal.preloadFonts();
await requestMain(clusterSetFrameIdHandler, clusterId, frameId);
await requestMain(clusterSetFrameIdHandler, clusterId);
await getHostedCluster().whenReady; // cluster.activate() is done at this point
extensionLoader.loadOnClusterRenderer();
setTimeout(() => {