diff --git a/src/common/cluster-frames.ts b/src/common/cluster-frames.ts index cf82bc4646..951e12c85b 100644 --- a/src/common/cluster-frames.ts +++ b/src/common/cluster-frames.ts @@ -1,3 +1,8 @@ import { observable } from "mobx"; -export const clusterFrameMap = observable.map(); +export type ClusterFrameInfo = { + frameId: number; + processId: number +}; + +export const clusterFrameMap = observable.map(); diff --git a/src/common/cluster-ipc.ts b/src/common/cluster-ipc.ts index 48626f5307..d44634407e 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/cluster-ipc.ts @@ -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(); } diff --git a/src/common/ipc.ts b/src/common/ipc.ts index 628aa503f8..369221815b 100644 --- a/src/common/ipc.ts +++ b/src/common/ipc.ts @@ -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 { - const subFrames: number[] = []; +async function getSubFrames(): Promise { + 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); }); diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index b1af7d69ac..bf7458afa0 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -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(); } diff --git a/src/renderer/components/app.tsx b/src/renderer/components/app.tsx index 58cd45b618..495182b2a9 100755 --- a/src/renderer/components/app.tsx +++ b/src/renderer/components/app.tsx @@ -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(() => {