mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
extract ipc renderer navigation events to const enum to avoid names duplication
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
2f9541f96f
commit
08bff81bf3
@ -8,6 +8,7 @@ import { initMenu } from "./menu";
|
||||
import { initTray } from "./tray";
|
||||
import { Singleton } from "../common/utils";
|
||||
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
|
||||
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||
import logger from "./logger";
|
||||
|
||||
export class WindowManager extends Singleton {
|
||||
@ -65,13 +66,13 @@ export class WindowManager extends Singleton {
|
||||
shell.openExternal(url);
|
||||
});
|
||||
this.mainWindow.webContents.on("dom-ready", () => {
|
||||
appEventBus.emit({name: "app", action: "dom-ready"});
|
||||
appEventBus.emit({ name: "app", action: "dom-ready" });
|
||||
});
|
||||
this.mainWindow.on("focus", () => {
|
||||
appEventBus.emit({name: "app", action: "focus"});
|
||||
appEventBus.emit({ name: "app", action: "focus" });
|
||||
});
|
||||
this.mainWindow.on("blur", () => {
|
||||
appEventBus.emit({name: "app", action: "blur"});
|
||||
appEventBus.emit({ name: "app", action: "blur" });
|
||||
});
|
||||
|
||||
// clean up
|
||||
@ -115,7 +116,7 @@ export class WindowManager extends Singleton {
|
||||
|
||||
protected bindEvents() {
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
@ -139,7 +140,9 @@ export class WindowManager extends Singleton {
|
||||
await this.ensureMainWindow();
|
||||
|
||||
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({
|
||||
channel,
|
||||
@ -152,7 +155,7 @@ export class WindowManager extends Singleton {
|
||||
const frameInfo = clusterFrameMap.get(this.activeClusterId);
|
||||
|
||||
if (frameInfo) {
|
||||
this.sendToView({ channel: "renderer:reload", frameInfo });
|
||||
this.sendToView({ channel: IpcRendererNavigationEvents.RELOAD_PAGE, frameInfo });
|
||||
} else {
|
||||
webContents.getFocusedWebContents()?.reload();
|
||||
}
|
||||
|
||||
@ -4,6 +4,13 @@ import { getMatchedClusterId, navigate } from "./helpers";
|
||||
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
|
||||
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",
|
||||
}
|
||||
|
||||
export function bindEvents() {
|
||||
if (!ipcRenderer) {
|
||||
return;
|
||||
@ -16,7 +23,7 @@ export function bindEvents() {
|
||||
}
|
||||
|
||||
// Reload dashboard window
|
||||
subscribeToBroadcast("renderer:reload", () => {
|
||||
subscribeToBroadcast(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
@ -25,13 +32,13 @@ export function bindEvents() {
|
||||
function bindClusterManagerRouteEvents() {
|
||||
// Keep track of active cluster-id for handling IPC/menus/etc.
|
||||
reaction(() => getMatchedClusterId(), clusterId => {
|
||||
broadcastMessage("cluster-view:current-id", clusterId);
|
||||
broadcastMessage(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, clusterId);
|
||||
}, {
|
||||
fireImmediately: true
|
||||
});
|
||||
|
||||
// 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 });
|
||||
navigate(url);
|
||||
});
|
||||
@ -39,7 +46,7 @@ function bindClusterManagerRouteEvents() {
|
||||
|
||||
// Handle cluster-view renderer process events within iframes
|
||||
function bindClusterFrameRouteEvents() {
|
||||
subscribeToBroadcast("renderer:navigate-in-cluster", (event, url: string) => {
|
||||
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
|
||||
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
|
||||
navigate(url);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user