From 78ea32eaa3c6e2f45347a57c7346d31141d737ee Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 28 Jul 2021 08:18:10 -0400 Subject: [PATCH] Fix open in new window Signed-off-by: Sebastian Malton --- src/main/initializers/ipc.ts | 6 +----- src/main/window-manager.ts | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/initializers/ipc.ts b/src/main/initializers/ipc.ts index c966407516..4b88ba4a34 100644 --- a/src/main/initializers/ipc.ts +++ b/src/main/initializers/ipc.ts @@ -26,7 +26,6 @@ import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHand import { ClusterId, ClusterStore } from "../../common/cluster-store"; import { appEventBus } from "../../common/event-bus"; import { ipcMainHandle, onNewWindowForClusterHandler } from "../../common/ipc"; -import { IpcRendererNavigationEvents } from "../../renderer/navigation/events"; import { catalogEntityRegistry } from "../catalog"; import { ClusterManager } from "../cluster-manager"; import { bundledKubectlPath } from "../kubectl"; @@ -163,10 +162,7 @@ export function initIpcMainHandlers() { } try { - const wm = WindowManager.getInstance(); - const window = await wm.openNewWindow(); - - window.webContents.send(IpcRendererNavigationEvents.NAVIGATE_IN_APP, `/cluster/${clusterId}`); + await WindowManager.getInstance().navigate(`/cluster/${clusterId}`, { clusterId }, { windowId: true }); } catch (error) { logger.error("Failed to load url for new cluster window", error); } diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 6c30f8c8c4..7f2543ba68 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -41,8 +41,17 @@ export interface SendToViewArgs { } export interface NavigateFrameInfoSpecifier { - windowId?: number; + /** + * The windowId of the window to navigate to or `true` to open a new window + */ + windowId?: number | true; + /** + * The clusterId that should have a related frame to navigate to + */ clusterId?: string; + /** + * The specific frame to navigate to + */ frameId?: number; } @@ -158,12 +167,12 @@ export class WindowManager extends Singleton { return browserWindow; } - async ensureWindow(windowId?: number): Promise { + async ensureWindow(windowId?: number | true): Promise { // This needs to be ready to hear the IPC message before the window is loaded let viewHasLoaded = Promise.resolve(); let browserWindow: BrowserWindow; - if (this.windows.size === 0) { + if (this.windows.size === 0 || windowId === true) { viewHasLoaded = new Promise(resolve => { ipcMain.once(IpcRendererNavigationEvents.LOADED, () => resolve()); }); @@ -236,8 +245,8 @@ export class WindowManager extends Singleton { * Get the naviate target * @param specifics The fallback options for specifying a target */ - private getNavigateTarget(specifics: NavigateFrameInfoSpecifier[]): [ClusterFrameInfo | undefined, number | undefined] { - function* helper(): Iterable { + private getNavigateTarget(specifics: NavigateFrameInfoSpecifier[]): [ClusterFrameInfo | undefined, number | true | undefined] { + function* helper(): Iterable { const clusterFrames = ClusterFrames.getInstance(); for (const fallback of specifics) { @@ -251,7 +260,7 @@ export class WindowManager extends Singleton { continue; } - if (typeof fallback.windowId === "number") { + if (typeof fallback.windowId === "number" || fallback.windowId === true) { yield fallback.windowId; } } @@ -261,7 +270,7 @@ export class WindowManager extends Singleton { const target = iter.first(iter.keepDefined(helper())); - if (typeof target === "number") { + if (typeof target === "number" || target === true) { return [undefined, target]; }