mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move deactivating a cluster into injectable IPC (#7356)
* Move activating cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move deactivating a cluster into injectable IPC Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
497f63fde6
commit
ae9a8c3c41
16 files changed
+111
-96
No files matched your search
@@ -6,15 +6,11 @@
|
||||
import type { CatalogEntityActionContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus, CatalogCategorySpec } from "../catalog";
|
||||
import { CatalogEntity, CatalogCategory, categoryVersion } from "../catalog/catalog-entity";
|
||||
import { broadcastMessage } from "../ipc";
|
||||
import { app } from "electron";
|
||||
import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||
import { IpcRendererNavigationEvents } from "../ipc/navigation-events";
|
||||
import { requestClusterDisconnection } from "../../renderer/ipc";
|
||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
||||
import getClusterByIdInjectable from "../cluster-store/get-by-id.injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import clusterConnectionInjectable from "../../main/cluster/cluster-connection.injectable";
|
||||
import { requestClusterActivationInjectionToken } from "../../features/cluster/activation/common/request-token";
|
||||
import { requestClusterActivationInjectionToken, requestClusterDeactivationInjectionToken } from "../../features/cluster/activation/common/request-token";
|
||||
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
address?: {
|
||||
@@ -87,21 +83,10 @@ export class KubernetesCluster<
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (app) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
const cluster = getClusterById(this.getId());
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const requestClusterDeactivation = di.inject(requestClusterDeactivationInjectionToken);
|
||||
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connectionCluster = di.inject(clusterConnectionInjectable, cluster);
|
||||
|
||||
connectionCluster.disconnect();
|
||||
} else {
|
||||
await requestClusterDisconnection(this.getId(), false);
|
||||
}
|
||||
await requestClusterDeactivation(this.getId());
|
||||
}
|
||||
|
||||
async onRun(context: CatalogEntityActionContext) {
|
||||
@@ -135,7 +120,7 @@ export class KubernetesCluster<
|
||||
title: "Disconnect",
|
||||
icon: "link_off",
|
||||
onClick: () => {
|
||||
requestClusterDisconnection(this.getId());
|
||||
this.disconnect();
|
||||
broadcastMessage(
|
||||
IpcRendererNavigationEvents.NAVIGATE_IN_APP,
|
||||
"/catalog",
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { clusterFrameMap } from "./cluster-frames";
|
||||
import { observable } from "mobx";
|
||||
|
||||
export interface ClusterFrameInfo {
|
||||
frameId: number;
|
||||
processId: number;
|
||||
}
|
||||
|
||||
const clusterFramesInjectable = getInjectable({
|
||||
id: "cluster-frames",
|
||||
instantiate: () => clusterFrameMap,
|
||||
causesSideEffects: true,
|
||||
instantiate: () => observable.map<string, ClusterFrameInfo>(),
|
||||
});
|
||||
|
||||
export default clusterFramesInjectable;
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { observable } from "mobx";
|
||||
|
||||
export interface ClusterFrameInfo {
|
||||
frameId: number;
|
||||
processId: number;
|
||||
}
|
||||
|
||||
export const clusterFrameMap = observable.map<string, ClusterFrameInfo>();
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
||||
export const clusterVisibilityHandler = "cluster:visibility";
|
||||
export const clusterDisconnectHandler = "cluster:disconnect";
|
||||
export const clusterStates = "cluster:states";
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,13 +9,12 @@
|
||||
|
||||
import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||
import { toJS } from "../utils/toJS";
|
||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
||||
import { clusterFrameMap } from "../cluster-frames";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import ipcMainInjectionToken from "./ipc-main-injection-token";
|
||||
import clusterFramesInjectable from "../cluster-frames.injectable";
|
||||
|
||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||
|
||||
@@ -29,10 +28,6 @@ export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMai
|
||||
});
|
||||
}
|
||||
|
||||
function getSubFrames(): ClusterFrameInfo[] {
|
||||
return Array.from(clusterFrameMap.values());
|
||||
}
|
||||
|
||||
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
|
||||
if (ipcRenderer) {
|
||||
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
|
||||
@@ -44,12 +39,12 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
||||
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const clusterFrames = di.inject(clusterFramesInjectable);
|
||||
|
||||
ipcMain.listeners(channel).forEach((func) => func({
|
||||
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
||||
}, ...args));
|
||||
|
||||
const subFrames = getSubFrames();
|
||||
const views = webContents.getAllWebContents();
|
||||
|
||||
if (!views || !Array.isArray(views) || views.length === 0) return;
|
||||
@@ -75,7 +70,7 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
||||
}
|
||||
|
||||
// Send message to subFrames of views.
|
||||
for (const frameInfo of subFrames) {
|
||||
for (const frameInfo of clusterFrames.values()) {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user