mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix: incorrect subscribing event name to navigate in cluster view (#2363)
Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
e718b250cc
commit
62c3501011
@ -29,6 +29,7 @@ import { LensProtocolRouterMain } from "./protocol-handler";
|
|||||||
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
import { getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||||
import { bindBroadcastHandlers } from "../common/ipc";
|
import { bindBroadcastHandlers } from "../common/ipc";
|
||||||
import { startUpdateChecking } from "./app-updater";
|
import { startUpdateChecking } from "./app-updater";
|
||||||
|
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||||
|
|
||||||
const workingDir = path.join(app.getPath("appData"), appName);
|
const workingDir = path.join(app.getPath("appData"), appName);
|
||||||
let proxyPort: number;
|
let proxyPort: number;
|
||||||
@ -162,7 +163,7 @@ app.on("ready", async () => {
|
|||||||
windowManager.initMainWindow();
|
windowManager.initMainWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on("renderer:loaded", () => {
|
ipcMain.on(IpcRendererNavigationEvents.LOADED, () => {
|
||||||
startUpdateChecking();
|
startUpdateChecking();
|
||||||
LensProtocolRouterMain
|
LensProtocolRouterMain
|
||||||
.getInstance<LensProtocolRouterMain>()
|
.getInstance<LensProtocolRouterMain>()
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { initMenu } from "./menu";
|
|||||||
import { initTray } from "./tray";
|
import { initTray } from "./tray";
|
||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
||||||
|
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
|
|
||||||
export class WindowManager extends Singleton {
|
export class WindowManager extends Singleton {
|
||||||
@ -65,13 +66,13 @@ export class WindowManager extends Singleton {
|
|||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
});
|
});
|
||||||
this.mainWindow.webContents.on("dom-ready", () => {
|
this.mainWindow.webContents.on("dom-ready", () => {
|
||||||
appEventBus.emit({name: "app", action: "dom-ready"});
|
appEventBus.emit({ name: "app", action: "dom-ready" });
|
||||||
});
|
});
|
||||||
this.mainWindow.on("focus", () => {
|
this.mainWindow.on("focus", () => {
|
||||||
appEventBus.emit({name: "app", action: "focus"});
|
appEventBus.emit({ name: "app", action: "focus" });
|
||||||
});
|
});
|
||||||
this.mainWindow.on("blur", () => {
|
this.mainWindow.on("blur", () => {
|
||||||
appEventBus.emit({name: "app", action: "blur"});
|
appEventBus.emit({ name: "app", action: "blur" });
|
||||||
});
|
});
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
@ -115,7 +116,7 @@ export class WindowManager extends Singleton {
|
|||||||
|
|
||||||
protected bindEvents() {
|
protected bindEvents() {
|
||||||
// track visible cluster from ui
|
// track visible cluster from ui
|
||||||
subscribeToBroadcast("cluster-view:current-id", (event, clusterId: ClusterId) => {
|
subscribeToBroadcast(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, (event, clusterId: ClusterId) => {
|
||||||
this.activeClusterId = clusterId;
|
this.activeClusterId = clusterId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -139,7 +140,9 @@ export class WindowManager extends Singleton {
|
|||||||
await this.ensureMainWindow();
|
await this.ensureMainWindow();
|
||||||
|
|
||||||
const frameInfo = Array.from(clusterFrameMap.values()).find((frameInfo) => frameInfo.frameId === frameId);
|
const frameInfo = Array.from(clusterFrameMap.values()).find((frameInfo) => frameInfo.frameId === frameId);
|
||||||
const channel = frameInfo ? "renderer:navigate-in-cluster" : "renderer:navigate";
|
const channel = frameInfo
|
||||||
|
? IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER
|
||||||
|
: IpcRendererNavigationEvents.NAVIGATE_IN_APP;
|
||||||
|
|
||||||
this.sendToView({
|
this.sendToView({
|
||||||
channel,
|
channel,
|
||||||
@ -152,7 +155,7 @@ export class WindowManager extends Singleton {
|
|||||||
const frameInfo = clusterFrameMap.get(this.activeClusterId);
|
const frameInfo = clusterFrameMap.get(this.activeClusterId);
|
||||||
|
|
||||||
if (frameInfo) {
|
if (frameInfo) {
|
||||||
this.sendToView({ channel: "renderer:reload", frameInfo });
|
this.sendToView({ channel: IpcRendererNavigationEvents.RELOAD_PAGE, frameInfo });
|
||||||
} else {
|
} else {
|
||||||
webContents.getFocusedWebContents()?.reload();
|
webContents.getFocusedWebContents()?.reload();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,10 @@ import { clusterDisconnectHandler } from "../../../common/cluster-ipc";
|
|||||||
import { ConfirmDialog } from "../confirm-dialog";
|
import { ConfirmDialog } from "../confirm-dialog";
|
||||||
import { Cluster } from "../../../main/cluster";
|
import { Cluster } from "../../../main/cluster";
|
||||||
import { Tooltip } from "../../components//tooltip";
|
import { Tooltip } from "../../components//tooltip";
|
||||||
|
import { IpcRendererNavigationEvents } from "../../navigation/events";
|
||||||
|
|
||||||
const navigate = (route: string) =>
|
const navigate = (route: string) =>
|
||||||
broadcastMessage("renderer:navigate", route);
|
broadcastMessage(IpcRendererNavigationEvents.NAVIGATE_IN_APP, route);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates handlers for high-level actions
|
* Creates handlers for high-level actions
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import { workspaceStore } from "../../../../common/workspace-store";
|
|||||||
import { broadcastMessage, requestMain } from "../../../../common/ipc";
|
import { broadcastMessage, requestMain } from "../../../../common/ipc";
|
||||||
import { clusterDisconnectHandler } from "../../../../common/cluster-ipc";
|
import { clusterDisconnectHandler } from "../../../../common/cluster-ipc";
|
||||||
import { ConfirmDialog } from "../../confirm-dialog";
|
import { ConfirmDialog } from "../../confirm-dialog";
|
||||||
|
import { IpcRendererNavigationEvents } from "../../../navigation/events";
|
||||||
|
|
||||||
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
|
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
|
||||||
const mockRequestMain = requestMain as jest.MockedFunction<typeof requestMain>;
|
const mockRequestMain = requestMain as jest.MockedFunction<typeof requestMain>;
|
||||||
@ -76,7 +77,7 @@ describe("<MainLayoutHeader />", () => {
|
|||||||
|
|
||||||
it("navigates to cluster settings", () => {
|
it("navigates to cluster settings", () => {
|
||||||
fireEvent.click(settingsBtn);
|
fireEvent.click(settingsBtn);
|
||||||
expect(mockBroadcastIpc).toBeCalledWith("renderer:navigate", "/cluster/foo/settings");
|
expect(mockBroadcastIpc).toBeCalledWith(IpcRendererNavigationEvents.NAVIGATE_IN_APP, "/cluster/foo/settings");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("disconnects from cluster", () => {
|
it("disconnects from cluster", () => {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { CommandContainer } from "./components/command-palette/command-container
|
|||||||
import { LensProtocolRouterRenderer, bindProtocolAddRouteHandlers } from "./protocol-handler";
|
import { LensProtocolRouterRenderer, bindProtocolAddRouteHandlers } from "./protocol-handler";
|
||||||
import { registerIpcHandlers } from "./ipc";
|
import { registerIpcHandlers } from "./ipc";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
|
import { IpcRendererNavigationEvents } from "./navigation/events";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class LensApp extends React.Component {
|
export class LensApp extends React.Component {
|
||||||
@ -30,7 +31,7 @@ export class LensApp extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
registerIpcHandlers();
|
registerIpcHandlers();
|
||||||
ipcRenderer.send("renderer:loaded");
|
ipcRenderer.send(IpcRendererNavigationEvents.LOADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -4,6 +4,14 @@ import { getMatchedClusterId, navigate } from "./helpers";
|
|||||||
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
|
|
||||||
|
export const enum IpcRendererNavigationEvents {
|
||||||
|
RELOAD_PAGE = "renderer:page-reload",
|
||||||
|
CLUSTER_VIEW_CURRENT_ID = "renderer:cluster-id-of-active-view",
|
||||||
|
NAVIGATE_IN_APP = "renderer:navigate",
|
||||||
|
NAVIGATE_IN_CLUSTER = "renderer:navigate-in-cluster",
|
||||||
|
LOADED = "renderer:loaded",
|
||||||
|
}
|
||||||
|
|
||||||
export function bindEvents() {
|
export function bindEvents() {
|
||||||
if (!ipcRenderer) {
|
if (!ipcRenderer) {
|
||||||
return;
|
return;
|
||||||
@ -16,7 +24,7 @@ export function bindEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload dashboard window
|
// Reload dashboard window
|
||||||
subscribeToBroadcast("renderer:reload", () => {
|
subscribeToBroadcast(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -25,13 +33,13 @@ export function bindEvents() {
|
|||||||
function bindClusterManagerRouteEvents() {
|
function bindClusterManagerRouteEvents() {
|
||||||
// Keep track of active cluster-id for handling IPC/menus/etc.
|
// Keep track of active cluster-id for handling IPC/menus/etc.
|
||||||
reaction(() => getMatchedClusterId(), clusterId => {
|
reaction(() => getMatchedClusterId(), clusterId => {
|
||||||
broadcastMessage("cluster-view:current-id", clusterId);
|
broadcastMessage(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, clusterId);
|
||||||
}, {
|
}, {
|
||||||
fireImmediately: true
|
fireImmediately: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle navigation via IPC
|
// Handle navigation via IPC
|
||||||
subscribeToBroadcast("renderer:navigate", (event, url: string) => {
|
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
|
||||||
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
||||||
navigate(url);
|
navigate(url);
|
||||||
});
|
});
|
||||||
@ -39,7 +47,7 @@ function bindClusterManagerRouteEvents() {
|
|||||||
|
|
||||||
// Handle cluster-view renderer process events within iframes
|
// Handle cluster-view renderer process events within iframes
|
||||||
function bindClusterFrameRouteEvents() {
|
function bindClusterFrameRouteEvents() {
|
||||||
subscribeToBroadcast("renderer:navigate-cluster-view", (event, url: string) => {
|
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
|
||||||
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
||||||
navigate(url);
|
navigate(url);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user