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"; 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 { ClusterId, clusterStore } from "./cluster-store";
import { appEventBus } from "./event-bus"; import { appEventBus } from "./event-bus";
import { ResourceApplier } from "../main/resource-applier"; import { ResourceApplier } from "../main/resource-applier";
import { ipcMain } from "electron"; import { ipcMain, IpcMainInvokeEvent } from "electron";
import { clusterFrameMap } from "./cluster-frames"; import { clusterFrameMap } from "./cluster-frames";
export const clusterActivateHandler = "cluster:activate"; 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); const cluster = clusterStore.getById(clusterId);
if (cluster) { if (cluster) {
clusterFrameMap.set(cluster.id, frameId); clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
return cluster.pushState(); return cluster.pushState();
} }

View File

@ -4,7 +4,7 @@
import { ipcMain, ipcRenderer, webContents, remote } from "electron"; import { ipcMain, ipcRenderer, webContents, remote } from "electron";
import logger from "../main/logger"; 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) { export function handleRequest(channel: string, listener: (...args: any[]) => any) {
ipcMain.handle(channel, listener); ipcMain.handle(channel, listener);
@ -14,11 +14,11 @@ export async function requestMain(channel: string, ...args: any[]) {
return ipcRenderer.invoke(channel, ...args); return ipcRenderer.invoke(channel, ...args);
} }
async function getSubFrames(): Promise<number[]> { async function getSubFrames(): Promise<ClusterFrameInfo[]> {
const subFrames: number[] = []; const subFrames: ClusterFrameInfo[] = [];
clusterFrameMap.forEach(frameId => { clusterFrameMap.forEach(frameInfo => {
subFrames.push(frameId); subFrames.push(frameInfo);
}); });
return subFrames; return subFrames;
@ -35,8 +35,8 @@ 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) => { getSubFrames().then((frames) => {
frames.map((frameId) => { frames.map((frameInfo) => {
webContent.sendToFrame(frameId, channel, ...args); webContent.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
}); });
}).catch((e) => e); }).catch((e) => e);
}); });

View File

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

View File

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