Switch to more specific IPC helpers (#2821)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-06-10 10:34:22 -04:00
1 parent a12cb0a16e
commit 280af6391e
18 files changed
+191 -178

No files matched your search

+3 -3
View File
@@ -20,8 +20,8 @@
*/
import { computed, observable, makeObservable, action } from "mobx";
import { subscribeToBroadcast } from "../../common/ipc";
import { CatalogCategory, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../../common/catalog";
import { ipcRendererOn } from "../../common/ipc";
import { CatalogCategory, CatalogEntity, CatalogEntityData, catalogCategoryRegistry, CatalogCategoryRegistry, CatalogEntityKindData } from "../../common/catalog";
import "../../common/catalog-entities";
import type { Cluster } from "../../main/cluster";
import { ClusterStore } from "../../common/cluster-store";
@@ -40,7 +40,7 @@ export class CatalogEntityRegistry {
}
init() {
subscribeToBroadcast("catalog:items", (ev, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
ipcRendererOn("catalog:items", (event, items: (CatalogEntityData & CatalogEntityKindData)[]) => {
this.updateItems(items);
});
}
@@ -27,7 +27,7 @@ import { observer } from "mobx-react";
import React from "react";
import { clusterActivateHandler } from "../../../common/cluster-ipc";
import { ClusterId, ClusterStore } from "../../../common/cluster-store";
import { requestMain, subscribeToBroadcast } from "../../../common/ipc";
import { ipcRendererOn, requestMain } from "../../../common/ipc";
import type { Cluster } from "../../../main/cluster";
import { cssNames, IClassName } from "../../utils";
import { Button } from "../button";
@@ -61,7 +61,7 @@ export class ClusterStatus extends React.Component<Props> {
}
async componentDidMount() {
subscribeToBroadcast(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
ipcRendererOn(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
this.authOutput.push({
data: res.data.trimRight(),
error: res.error,
@@ -26,7 +26,7 @@ import { observer } from "mobx-react";
import React from "react";
import { Dialog } from "../dialog";
import { EventEmitter } from "../../../common/event-emitter";
import { subscribeToBroadcast } from "../../../common/ipc";
import { ipcRendererOn } from "../../../common/ipc";
import { CommandDialog } from "./command-dialog";
import type { ClusterId } from "../../../common/cluster-store";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
@@ -85,7 +85,7 @@ export class CommandContainer extends React.Component<CommandContainerProps> {
componentDidMount() {
if (this.props.clusterId) {
subscribeToBroadcast(`command-palette:run-action:${this.props.clusterId}`, (event, commandId: string) => {
ipcRendererOn(`command-palette:run-action:${this.props.clusterId}`, (event, commandId: string) => {
const command = this.findCommandById(commandId);
if (command) {
@@ -93,8 +93,8 @@ export class CommandContainer extends React.Component<CommandContainerProps> {
}
});
} else {
subscribeToBroadcast("command-palette:open", () => {
this.commandComponent = <CommandDialog />;
ipcRendererOn("command-palette:open", () => {
CommandOverlay.open(<CommandDialog />);
});
}
window.addEventListener("keyup", (e) => this.escHandler(e), true);
+4 -4
View File
@@ -22,7 +22,7 @@
import { ipcRenderer } from "electron";
import { reaction } from "mobx";
import { getMatchedClusterId, navigate } from "./helpers";
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
import { broadcastMessage, ipcRendererOn } from "../../common/ipc";
import logger from "../../main/logger";
export const enum IpcRendererNavigationEvents {
@@ -45,7 +45,7 @@ export function bindEvents() {
}
// Reload dashboard window
subscribeToBroadcast(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
ipcRendererOn(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
location.reload();
});
}
@@ -60,7 +60,7 @@ function bindClusterManagerRouteEvents() {
});
// Handle navigation via IPC
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
ipcRendererOn(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
navigate(url);
});
@@ -68,7 +68,7 @@ function bindClusterManagerRouteEvents() {
// Handle cluster-view renderer process events within iframes
function bindClusterFrameRouteEvents() {
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
ipcRendererOn(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
navigate(url);
});