1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-11-18 14:54:29 +02:00
parent 5b0efe2c86
commit 93bc8fcb86
6 changed files with 22 additions and 11 deletions

View File

@ -4,15 +4,21 @@ import { appEventBus } from "./event-bus"
import { ResourceApplier } from "../main/resource-applier"; import { ResourceApplier } from "../main/resource-applier";
import { ipcMain } from "electron"; import { ipcMain } from "electron";
export const clusterActivateHandler = "cluster:activate"
export const clusterSetFrameIdHandler = "cluster:set-frame-id"
export const clusterRefreshHandler = "cluster:refresh"
export const clusterDisconnectHandler = "cluster:disconnect"
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all"
if (ipcMain) { if (ipcMain) {
handleRequest("cluster:activate", (event, clusterId: ClusterId, force = false) => { handleRequest(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
if (cluster) { if (cluster) {
return cluster.activate(force); return cluster.activate(force);
} }
}) })
handleRequest("cluster:set-frame-id", (event, clusterId: ClusterId, frameId?: number) => { handleRequest(clusterSetFrameIdHandler, (event, clusterId: ClusterId, frameId?: number) => {
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
if (cluster) { if (cluster) {
if (frameId) cluster.frameId = frameId; // save cluster's webFrame.routingId to be able to send push-updates if (frameId) cluster.frameId = frameId; // save cluster's webFrame.routingId to be able to send push-updates
@ -20,17 +26,17 @@ if (ipcMain) {
} }
}) })
handleRequest("cluster:refresh", (event, clusterId: ClusterId) => { handleRequest(clusterRefreshHandler, (event, clusterId: ClusterId) => {
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
if (cluster) return cluster.refresh({ refreshMetadata: true }) if (cluster) return cluster.refresh({ refreshMetadata: true })
}) })
handleRequest("cluster:disconnect", (event, clusterId: ClusterId) => { handleRequest(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
appEventBus.emit({name: "cluster", action: "stop"}); appEventBus.emit({name: "cluster", action: "stop"});
return clusterStore.getById(clusterId)?.disconnect(); return clusterStore.getById(clusterId)?.disconnect();
}) })
handleRequest("cluster:kubectl-apply-all", (event, clusterId: ClusterId, resources: string[]) => { handleRequest(clusterKubectlApplyAllHandler, (event, clusterId: ClusterId, resources: string[]) => {
appEventBus.emit({name: "cluster", action: "kubectl-apply-all"}) appEventBus.emit({name: "cluster", action: "kubectl-apply-all"})
const cluster = clusterStore.getById(clusterId); const cluster = clusterStore.getById(clusterId);
if (cluster) { if (cluster) {

View File

@ -7,6 +7,7 @@ import { Cluster } from "../main/cluster";
import logger from "../main/logger"; import logger from "../main/logger";
import { app } from "electron" import { app } from "electron"
import { requestMain } from "../common/ipc"; import { requestMain } from "../common/ipc";
import { clusterKubectlApplyAllHandler } from "../common/cluster-ipc";
export interface ClusterFeatureStatus { export interface ClusterFeatureStatus {
currentVersion: string; currentVersion: string;
@ -39,7 +40,7 @@ export abstract class ClusterFeature {
if (app) { if (app) {
await new ResourceApplier(cluster).kubectlApplyAll(resources) await new ResourceApplier(cluster).kubectlApplyAll(resources)
} else { } else {
await requestMain("cluster:kubectl-apply-all", cluster.id, resources) await requestMain(clusterKubectlApplyAllHandler, cluster.id, resources)
} }
} }

View File

@ -14,6 +14,7 @@ import { IClusterSettingsRouteParams } from "./cluster-settings.route";
import { clusterStore } from "../../../common/cluster-store"; import { clusterStore } from "../../../common/cluster-store";
import { PageLayout } from "../layout/page-layout"; import { PageLayout } from "../layout/page-layout";
import { requestMain } from "../../../common/ipc"; import { requestMain } from "../../../common/ipc";
import { clusterActivateHandler, clusterRefreshHandler } from "../../../common/cluster-ipc"
interface Props extends RouteComponentProps<IClusterSettingsRouteParams> { interface Props extends RouteComponentProps<IClusterSettingsRouteParams> {
} }
@ -41,8 +42,8 @@ export class ClusterSettings extends React.Component<Props> {
refreshCluster = async () => { refreshCluster = async () => {
if (this.cluster) { if (this.cluster) {
await requestMain("cluster:activate", this.cluster.id) await requestMain(clusterActivateHandler, this.cluster.id)
await requestMain("cluster:refresh", this.cluster.id) await requestMain(clusterRefreshHandler, this.cluster.id)
} }
} }

View File

@ -39,6 +39,7 @@ import { extensionLoader } from "../../extensions/extension-loader";
import { appEventBus } from "../../common/event-bus" import { appEventBus } from "../../common/event-bus"
import { requestMain } from "../../common/ipc"; import { requestMain } from "../../common/ipc";
import whatInput from 'what-input'; import whatInput from 'what-input';
import { clusterSetFrameIdHandler } from "../../common/cluster-ipc";
@observer @observer
export class App extends React.Component { 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}`) logger.info(`[APP]: Init dashboard, clusterId=${clusterId}, frameId=${frameId}`)
await Terminal.preloadFonts() await Terminal.preloadFonts()
await requestMain("cluster:set-frame-id", clusterId, frameId) await requestMain(clusterSetFrameIdHandler, clusterId, frameId)
await getHostedCluster().whenReady; // cluster.activate() is done at this point await getHostedCluster().whenReady; // cluster.activate() is done at this point
extensionLoader.loadOnClusterRenderer(); extensionLoader.loadOnClusterRenderer();
appEventBus.emit({ appEventBus.emit({

View File

@ -12,6 +12,7 @@ import { cssNames, IClassName } from "../../utils";
import { Cluster } from "../../../main/cluster"; import { Cluster } from "../../../main/cluster";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { CubeSpinner } from "../spinner"; import { CubeSpinner } from "../spinner";
import { clusterActivateHandler } from "../../../common/cluster-ipc";
interface Props { interface Props {
className?: IClassName; className?: IClassName;
@ -48,7 +49,7 @@ export class ClusterStatus extends React.Component<Props> {
} }
activateCluster = async (force = false) => { activateCluster = async (force = false) => {
await requestMain("cluster:activate", this.props.clusterId, force) await requestMain(clusterActivateHandler, this.props.clusterId, force)
} }
reconnect = async () => { reconnect = async () => {

View File

@ -23,6 +23,7 @@ import { Tooltip } from "../tooltip";
import { ConfirmDialog } from "../confirm-dialog"; import { ConfirmDialog } from "../confirm-dialog";
import { clusterViewURL } from "./cluster-view.route"; import { clusterViewURL } from "./cluster-view.route";
import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries"; import { getExtensionPageUrl, globalPageMenuRegistry, globalPageRegistry } from "../../../extensions/registries";
import { clusterDisconnectHandler } from "../../../common/cluster-ipc";
interface Props { interface Props {
className?: IClassName; className?: IClassName;
@ -60,7 +61,7 @@ export class ClustersMenu extends React.Component<Props> {
navigate(landingURL()); navigate(landingURL());
clusterStore.setActive(null); clusterStore.setActive(null);
} }
await requestMain("cluster:disconnect", cluster.id) await requestMain(clusterDisconnectHandler, cluster.id)
} }
})) }))
} }