Refactor ipc module (#1225)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2020-11-19 11:48:13 +02:00
1 parent c4b98534dc
commit 5aaacb21f9
20 files changed
+224 -242

No files matched your search

@@ -12,8 +12,9 @@ import { Cluster } from "../../../main/cluster";
import { ClusterIcon } from "../cluster-icon";
import { IClusterSettingsRouteParams } from "./cluster-settings.route";
import { clusterStore } from "../../../common/cluster-store";
import { clusterIpc } from "../../../common/cluster-ipc";
import { PageLayout } from "../layout/page-layout";
import { requestMain } from "../../../common/ipc";
import { clusterActivateHandler, clusterRefreshHandler } from "../../../common/cluster-ipc"
interface Props extends RouteComponentProps<IClusterSettingsRouteParams> {
}
@@ -41,8 +42,8 @@ export class ClusterSettings extends React.Component<Props> {
refreshCluster = async () => {
if (this.cluster) {
await clusterIpc.activate.invokeFromRenderer(this.cluster.id);
await clusterIpc.refresh.invokeFromRenderer(this.cluster.id);
await requestMain(clusterActivateHandler, this.cluster.id)
await requestMain(clusterRefreshHandler, this.cluster.id)
}
}
@@ -1,7 +1,6 @@
import React from "react";
import { Trans } from "@lingui/macro";
import { observer } from "mobx-react";
import { clusterIpc } from "../../../../common/cluster-ipc";
import { clusterStore } from "../../../../common/cluster-store";
import { Cluster } from "../../../../main/cluster";
import { autobind } from "../../../utils";
+4 -3
View File
@@ -33,12 +33,13 @@ import { ErrorBoundary } from "./error-boundary";
import { Terminal } from "./dock/terminal";
import { getHostedCluster, getHostedClusterId } from "../../common/cluster-store";
import logger from "../../main/logger";
import { clusterIpc } from "../../common/cluster-ipc";
import { webFrame } from "electron";
import { clusterPageRegistry } from "../../extensions/registries/page-registry";
import { extensionLoader } from "../../extensions/extension-loader";
import { appEventBus } from "../../common/event-bus";
import { appEventBus } from "../../common/event-bus"
import { requestMain } from "../../common/ipc";
import whatInput from 'what-input';
import { clusterSetFrameIdHandler } from "../../common/cluster-ipc";
@observer
export class App extends React.Component {
@@ -48,7 +49,7 @@ export class App extends React.Component {
logger.info(`[APP]: Init dashboard, clusterId=${clusterId}, frameId=${frameId}`)
await Terminal.preloadFonts()
await clusterIpc.setFrameId.invokeFromRenderer(clusterId, frameId);
await requestMain(clusterSetFrameIdHandler, clusterId, frameId)
await getHostedCluster().whenReady; // cluster.activate() is done at this point
extensionLoader.loadOnClusterRenderer();
appEventBus.emit({
@@ -5,13 +5,14 @@ import React from "react";
import { observer } from "mobx-react";
import { ipcRenderer } from "electron";
import { computed, observable } from "mobx";
import { clusterIpc } from "../../../common/cluster-ipc";
import { requestMain, subscribeToBroadcast } from "../../../common/ipc";
import { Icon } from "../icon";
import { Button } from "../button";
import { cssNames, IClassName } from "../../utils";
import { Cluster } from "../../../main/cluster";
import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { CubeSpinner } from "../spinner";
import { clusterActivateHandler } from "../../../common/cluster-ipc";
interface Props {
className?: IClassName;
@@ -32,7 +33,7 @@ export class ClusterStatus extends React.Component<Props> {
}
async componentDidMount() {
ipcRenderer.on(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
subscribeToBroadcast(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
this.authOutput.push({
data: res.data.trimRight(),
error: res.error,
@@ -48,7 +49,7 @@ export class ClusterStatus extends React.Component<Props> {
}
activateCluster = async (force = false) => {
await clusterIpc.activate.invokeFromRenderer(this.props.clusterId, force);
await requestMain(clusterActivateHandler, this.props.clusterId, force)
}
reconnect = async () => {
@@ -2,6 +2,7 @@ import "./clusters-menu.scss"
import React from "react";
import { remote } from "electron"
import { requestMain } from "../../../common/ipc";
import type { Cluster } from "../../../main/cluster";
import { DragDropContext, Draggable, DraggableProvided, Droppable, DroppableProvided, DropResult } from "react-beautiful-dnd";
import { observer } from "mobx-react";
@@ -20,9 +21,9 @@ import { clusterSettingsURL } from "../+cluster-settings";
import { landingURL } from "../+landing-page";
import { Tooltip } from "../tooltip";
import { ConfirmDialog } from "../confirm-dialog";
import { clusterIpc } from "../../../common/cluster-ipc";
import { clusterViewURL } from "./cluster-view.route";
import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries";
import { clusterDisconnectHandler } from "../../../common/cluster-ipc";
interface Props {
className?: IClassName;
@@ -60,7 +61,7 @@ export class ClustersMenu extends React.Component<Props> {
navigate(landingURL());
clusterStore.setActive(null);
}
await clusterIpc.disconnect.invokeFromRenderer(cluster.id);
await requestMain(clusterDisconnectHandler, cluster.id)
}
}))
}