mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge remote-tracking branch 'origin/master' into webpack5-upgrade-attempt
# Conflicts: # src/common/catalog-entities/kubernetes-cluster.ts
This commit is contained in:
commit
398af8cc07
78 files changed
+657
-590
No files matched your search
@@ -4,45 +4,61 @@
|
||||
*/
|
||||
|
||||
import { anyObject } from "jest-mock-extended";
|
||||
import { merge } from "lodash";
|
||||
import mockFs from "mock-fs";
|
||||
import logger from "../../main/logger";
|
||||
import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog";
|
||||
import { HotbarStore } from "../hotbar-store";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import directoryForUserDataInjectable
|
||||
from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
jest.mock("../../main/catalog/catalog-entity-registry", () => ({
|
||||
catalogEntityRegistry: {
|
||||
items: [
|
||||
{
|
||||
getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
kind: "Cluster",
|
||||
status: {
|
||||
phase: "Running",
|
||||
},
|
||||
metadata: {
|
||||
uid: "1dfa26e2ebab15780a3547e9c7fa785c",
|
||||
name: "mycluster",
|
||||
source: "local",
|
||||
labels: {},
|
||||
},
|
||||
}),
|
||||
getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
kind: "Cluster",
|
||||
status: {
|
||||
phase: "Running",
|
||||
},
|
||||
},
|
||||
{
|
||||
metadata: {
|
||||
uid: "55b42c3c7ba3b04193416cda405269a5",
|
||||
name: "my_shiny_cluster",
|
||||
source: "remote",
|
||||
labels: {},
|
||||
},
|
||||
}),
|
||||
getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
kind: "Cluster",
|
||||
status: {
|
||||
phase: "Running",
|
||||
},
|
||||
},
|
||||
{
|
||||
metadata: {
|
||||
uid: "catalog-entity",
|
||||
name: "Catalog",
|
||||
source: "app",
|
||||
labels: {},
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
}));
|
||||
|
||||
function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity {
|
||||
return merge(data, {
|
||||
return {
|
||||
getName: jest.fn(() => data.metadata?.name),
|
||||
getId: jest.fn(() => data.metadata?.uid),
|
||||
getSource: jest.fn(() => data.metadata?.source ?? "unknown"),
|
||||
@@ -52,7 +68,8 @@ function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKi
|
||||
metadata: {},
|
||||
spec: {},
|
||||
status: {},
|
||||
}) as CatalogEntity;
|
||||
...data,
|
||||
} as CatalogEntity;
|
||||
}
|
||||
|
||||
const testCluster = getMockCatalogEntity({
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus, CatalogCategory, CatalogCategorySpec } from "../catalog";
|
||||
import { clusterActivateHandler, clusterDisconnectHandler } from "../cluster-ipc";
|
||||
import { ClusterStore } from "../cluster-store/cluster-store";
|
||||
import { broadcastMessage, requestMain } from "../ipc";
|
||||
import { broadcastMessage } from "../ipc";
|
||||
import { app } from "electron";
|
||||
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import { requestClusterActivation, requestClusterDisconnection } from "../../renderer/ipc";
|
||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg?raw";
|
||||
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
@@ -68,22 +68,22 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if (app) {
|
||||
await ClusterStore.getInstance().getById(this.metadata.uid)?.activate();
|
||||
await ClusterStore.getInstance().getById(this.getId())?.activate();
|
||||
} else {
|
||||
await requestMain(clusterActivateHandler, this.metadata.uid, false);
|
||||
await requestClusterActivation(this.getId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (app) {
|
||||
ClusterStore.getInstance().getById(this.metadata.uid)?.disconnect();
|
||||
ClusterStore.getInstance().getById(this.getId())?.disconnect();
|
||||
} else {
|
||||
await requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
||||
await requestClusterDisconnection(this.getId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
async onRun(context: CatalogEntityActionContext) {
|
||||
context.navigate(`/cluster/${this.metadata.uid}`);
|
||||
context.navigate(`/cluster/${this.getId()}`);
|
||||
}
|
||||
|
||||
onDetailsOpen(): void {
|
||||
@@ -101,7 +101,7 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
|
||||
icon: "settings",
|
||||
onClick: () => broadcastMessage(
|
||||
IpcRendererNavigationEvents.NAVIGATE_IN_APP,
|
||||
`/entity/${this.metadata.uid}/settings`,
|
||||
`/entity/${this.getId()}/settings`,
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -112,14 +112,14 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
|
||||
context.menuItems.push({
|
||||
title: "Disconnect",
|
||||
icon: "link_off",
|
||||
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid),
|
||||
onClick: () => requestClusterDisconnection(this.getId()),
|
||||
});
|
||||
break;
|
||||
case LensKubernetesClusterStatus.DISCONNECTED:
|
||||
context.menuItems.push({
|
||||
title: "Connect",
|
||||
icon: "link",
|
||||
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`),
|
||||
onClick: () => context.navigate(`/cluster/${this.getId()}`),
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
||||
context.menuItems.push({
|
||||
title: "Delete",
|
||||
icon: "delete",
|
||||
onClick: async () => WeblinkStore.getInstance().removeById(this.metadata.uid),
|
||||
onClick: async () => WeblinkStore.getInstance().removeById(this.getId()),
|
||||
confirm: {
|
||||
message: `Remove Web Link "${this.metadata.name}" from ${productName}?`,
|
||||
message: `Remove Web Link "${this.getName()}" from ${productName}?`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -315,11 +315,24 @@ export abstract class CatalogEntity<
|
||||
@observable status: Status;
|
||||
@observable spec: Spec;
|
||||
|
||||
constructor(data: CatalogEntityData<Metadata, Status, Spec>) {
|
||||
constructor({ metadata, status, spec }: CatalogEntityData<Metadata, Status, Spec>) {
|
||||
makeObservable(this);
|
||||
this.metadata = data.metadata;
|
||||
this.status = data.status;
|
||||
this.spec = data.spec;
|
||||
|
||||
if (!metadata || typeof metadata !== "object") {
|
||||
throw new TypeError("CatalogEntity's metadata must be a defined object");
|
||||
}
|
||||
|
||||
if (!status || typeof status !== "object") {
|
||||
throw new TypeError("CatalogEntity's status must be a defined object");
|
||||
}
|
||||
|
||||
if (!spec || typeof spec !== "object") {
|
||||
throw new TypeError("CatalogEntity's spec must be a defined object");
|
||||
}
|
||||
|
||||
this.metadata = metadata;
|
||||
this.status = status;
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import { ipcMain, ipcRenderer, webFrame } from "electron";
|
||||
import { action, comparer, computed, makeObservable, observable, reaction } from "mobx";
|
||||
@@ -11,16 +11,16 @@ import { Cluster } from "../cluster/cluster";
|
||||
import migrations from "../../migrations/cluster-store";
|
||||
import logger from "../../main/logger";
|
||||
import { appEventBus } from "../app-event-bus/event-bus";
|
||||
import { ipcMainHandle, requestMain } from "../ipc";
|
||||
import { ipcMainHandle } from "../ipc";
|
||||
import { disposer, toJS } from "../utils";
|
||||
import type { ClusterModel, ClusterId, ClusterState } from "../cluster-types";
|
||||
import { requestInitialClusterStates } from "../../renderer/ipc";
|
||||
import { clusterStates } from "../ipc/cluster";
|
||||
|
||||
export interface ClusterStoreModel {
|
||||
clusters?: ClusterModel[];
|
||||
}
|
||||
|
||||
const initialStates = "cluster:states";
|
||||
|
||||
interface Dependencies {
|
||||
createCluster: (model: ClusterModel) => Cluster
|
||||
}
|
||||
@@ -49,18 +49,18 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
async loadInitialOnRenderer() {
|
||||
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
||||
|
||||
for (const { id, state } of await requestMain(initialStates)) {
|
||||
for (const { id, state } of await requestInitialClusterStates()) {
|
||||
this.getById(id)?.setState(state);
|
||||
}
|
||||
}
|
||||
|
||||
provideInitialFromMain() {
|
||||
ipcMainHandle(initialStates, () => {
|
||||
return this.clustersList.map(cluster => ({
|
||||
ipcMainHandle(clusterStates, () => (
|
||||
this.clustersList.map(cluster => ({
|
||||
id: cluster.id,
|
||||
state: cluster.getState(),
|
||||
}));
|
||||
});
|
||||
}))
|
||||
));
|
||||
}
|
||||
|
||||
protected pushStateToViewsAutomatically() {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { ipcMain } from "electron";
|
||||
import { action, comparer, computed, makeObservable, observable, reaction, when } from "mobx";
|
||||
import { broadcastMessage, ClusterListNamespaceForbiddenChannel } from "../ipc";
|
||||
import { broadcastMessage } from "../ipc";
|
||||
import type { ContextHandler } from "../../main/context-handler/context-handler";
|
||||
import { AuthorizationV1Api, CoreV1Api, HttpError, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
||||
import type { Kubectl } from "../../main/kubectl/kubectl";
|
||||
@@ -20,6 +20,7 @@ import type { ClusterState, ClusterRefreshOptions, ClusterMetricsResourceType, C
|
||||
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../cluster-types";
|
||||
import { disposer, toJS } from "../utils";
|
||||
import type { Response } from "request";
|
||||
import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster";
|
||||
|
||||
interface Dependencies {
|
||||
directoryForKubeConfigs: string,
|
||||
@@ -641,7 +642,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
const { response } = error as HttpError & { response: Response };
|
||||
|
||||
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body });
|
||||
broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id);
|
||||
broadcastMessage(clusterListNamespaceForbiddenChannel, this.id);
|
||||
}
|
||||
|
||||
return namespaceList;
|
||||
|
||||
+21
-17
@@ -10,8 +10,9 @@ import { toJS } from "./utils";
|
||||
import { CatalogEntity } from "./catalog";
|
||||
import { catalogEntity } from "../main/catalog-sources/general";
|
||||
import logger from "../main/logger";
|
||||
import { broadcastMessage, HotbarTooManyItems } from "./ipc";
|
||||
import { broadcastMessage } from "./ipc";
|
||||
import { defaultHotbarCells, getEmptyHotbar, Hotbar, CreateHotbarData, CreateHotbarOptions } from "./hotbar-types";
|
||||
import { hotbarTooManyItemsChannel } from "./ipc/hotbar";
|
||||
|
||||
export interface HotbarStoreModel {
|
||||
hotbars: Hotbar[];
|
||||
@@ -153,28 +154,28 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
@action
|
||||
addToHotbar(item: CatalogEntity, cellIndex?: number) {
|
||||
const hotbar = this.getActive();
|
||||
const uid = item.metadata?.uid;
|
||||
const name = item.metadata?.name;
|
||||
const uid = item.getId();
|
||||
const name = item.getName();
|
||||
|
||||
if (typeof uid !== "string") {
|
||||
throw new TypeError("CatalogEntity.metadata.uid must be a string");
|
||||
throw new TypeError("CatalogEntity's ID must be a string");
|
||||
}
|
||||
|
||||
if (typeof name !== "string") {
|
||||
throw new TypeError("CatalogEntity.metadata.name must be a string");
|
||||
throw new TypeError("CatalogEntity's NAME must be a string");
|
||||
}
|
||||
|
||||
const newItem = { entity: {
|
||||
uid,
|
||||
name,
|
||||
source: item.metadata.source,
|
||||
}};
|
||||
|
||||
|
||||
if (this.isAddedToActive(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entity = {
|
||||
uid,
|
||||
name,
|
||||
source: item.metadata.source,
|
||||
};
|
||||
const newItem = { entity };
|
||||
|
||||
if (cellIndex === undefined) {
|
||||
// Add item to empty cell
|
||||
const emptyCellIndex = hotbar.items.indexOf(null);
|
||||
@@ -182,7 +183,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
if (emptyCellIndex != -1) {
|
||||
hotbar.items[emptyCellIndex] = newItem;
|
||||
} else {
|
||||
broadcastMessage(HotbarTooManyItems);
|
||||
broadcastMessage(hotbarTooManyItemsChannel);
|
||||
}
|
||||
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
|
||||
hotbar.items[cellIndex] = newItem;
|
||||
@@ -277,11 +278,14 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if entity already pinned to hotbar
|
||||
* @returns boolean
|
||||
* Checks if entity already pinned to the active hotbar
|
||||
*/
|
||||
isAddedToActive(entity: CatalogEntity) {
|
||||
return !!this.getActive().items.find(item => item?.entity.uid === entity.metadata.uid);
|
||||
isAddedToActive(entity: CatalogEntity | null | undefined): boolean {
|
||||
if (!entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getActive().items.findIndex(item => item?.entity.uid === entity.getId()) >= 0;
|
||||
}
|
||||
|
||||
getDisplayLabel(hotbar: Hotbar): string {
|
||||
|
||||
+13
-10
@@ -3,14 +3,17 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export enum CatalogIpcEvents {
|
||||
/**
|
||||
* This is broadcast on whenever there is an update to any catalog item
|
||||
*/
|
||||
ITEMS = "catalog:items",
|
||||
/**
|
||||
* This is used to activate a specific entity in the renderer main frame
|
||||
*/
|
||||
export const catalogEntityRunListener = "catalog-entity:run";
|
||||
|
||||
/**
|
||||
* This can be sent from renderer to main to initialize a broadcast of ITEMS
|
||||
*/
|
||||
INIT = "catalog:init",
|
||||
}
|
||||
/**
|
||||
* This is broadcast on whenever there is an update to any catalog item
|
||||
*/
|
||||
export const catalogItemsChannel = "catalog:items";
|
||||
|
||||
/**
|
||||
* This can be sent from renderer to main to initialize a broadcast of ITEMS
|
||||
*/
|
||||
export const catalogInitChannel = "catalog:init";
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This channel is broadcast on whenever the cluster fails to list namespaces
|
||||
* during a refresh and no `accessibleNamespaces` have been set.
|
||||
*/
|
||||
export const ClusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
|
||||
|
||||
export type ListNamespaceForbiddenArgs = [clusterId: string];
|
||||
|
||||
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
|
||||
return args.length === 1 && typeof args[0] === "string";
|
||||
}
|
||||
@@ -13,3 +13,16 @@ export const clusterSetDeletingHandler = "cluster:deleting:set";
|
||||
export const clusterClearDeletingHandler = "cluster:deleting:clear";
|
||||
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
||||
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
||||
export const clusterStates = "cluster:states";
|
||||
|
||||
/**
|
||||
* This channel is broadcast on whenever the cluster fails to list namespaces
|
||||
* during a refresh and no `accessibleNamespaces` have been set.
|
||||
*/
|
||||
export const clusterListNamespaceForbiddenChannel = "cluster:list-namespace-forbidden";
|
||||
|
||||
export type ListNamespaceForbiddenArgs = [clusterId: string];
|
||||
|
||||
export function isListNamespaceForbiddenArgs(args: unknown[]): args is ListNamespaceForbiddenArgs {
|
||||
return args.length === 1 && typeof args[0] === "string";
|
||||
}
|
||||
@@ -2,4 +2,5 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
export const BundledExtensionsLoaded = "extension-loader:bundled-extensions-loaded";
|
||||
|
||||
export const openFilePickingDialogChannel = "dialog:open:file-picking";
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export const extensionDiscoveryStateChannel = "extension-discovery:state";
|
||||
export const bundledExtensionsLoaded = "extension-loader:bundled-extensions-loaded";
|
||||
export const extensionLoaderFromMainChannel = "extension-loader:main:state";
|
||||
export const extensionLoaderFromRendererChannel = "extension-loader:renderer:state";
|
||||
@@ -3,4 +3,4 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export const HotbarTooManyItems = "hotbar:too-many-items";
|
||||
export const hotbarTooManyItemsChannel = "hotbar:too-many-items";
|
||||
@@ -3,13 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export const dialogShowOpenDialogHandler = "dialog:show-open-dialog";
|
||||
export const catalogEntityRunListener = "catalog-entity:run";
|
||||
|
||||
export * from "./ipc";
|
||||
export * from "./invalid-kubeconfig";
|
||||
export * from "./update-available.ipc";
|
||||
export * from "./cluster.ipc";
|
||||
export * from "./update-available";
|
||||
export * from "./type-enforced-ipc";
|
||||
export * from "./hotbar";
|
||||
export * from "./extension-loader.ipc";
|
||||
+41
-58
@@ -12,25 +12,8 @@ import { toJS } from "../utils/toJS";
|
||||
import logger from "../../main/logger";
|
||||
import { ClusterFrameInfo, clusterFrameMap } from "../cluster-frames";
|
||||
import type { Disposer } from "../utils";
|
||||
import type remote from "@electron/remote";
|
||||
|
||||
const electronRemote = (() => {
|
||||
if (ipcRenderer) {
|
||||
try {
|
||||
return require("@electron/remote");
|
||||
} catch {
|
||||
// ignore temp
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
})();
|
||||
|
||||
const subFramesChannel = "ipc:get-sub-frames";
|
||||
|
||||
export async function requestMain(channel: string, ...args: any[]) {
|
||||
return ipcRenderer.invoke(channel, ...args.map(sanitizePayload));
|
||||
}
|
||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||
|
||||
export function ipcMainHandle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any) {
|
||||
ipcMain.handle(channel, async (event, ...args) => {
|
||||
@@ -42,51 +25,55 @@ function getSubFrames(): ClusterFrameInfo[] {
|
||||
return Array.from(clusterFrameMap.values());
|
||||
}
|
||||
|
||||
export function broadcastMessage(channel: string, ...args: any[]) {
|
||||
const subFramesP = ipcRenderer
|
||||
? requestMain(subFramesChannel)
|
||||
: Promise.resolve(getSubFrames());
|
||||
export async function broadcastMessage(channel: string, ...args: any[]): Promise<void> {
|
||||
if (ipcRenderer) {
|
||||
return ipcRenderer.invoke(broadcastMainChannel, channel, ...args.map(sanitizePayload));
|
||||
}
|
||||
|
||||
subFramesP
|
||||
.then(subFrames => {
|
||||
const views: undefined | ReturnType<typeof webContents.getAllWebContents> | ReturnType<typeof remote.webContents.getAllWebContents> = (webContents || electronRemote?.webContents)?.getAllWebContents();
|
||||
if (!webContents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!views || !Array.isArray(views) || views.length === 0) return;
|
||||
args = args.map(sanitizePayload);
|
||||
ipcMain.listeners(channel).forEach((func) => func({
|
||||
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
||||
}, ...args));
|
||||
|
||||
ipcRenderer?.send(channel, ...args);
|
||||
ipcMain?.emit(channel, ...args);
|
||||
const subFrames = getSubFrames();
|
||||
const views = webContents.getAllWebContents();
|
||||
|
||||
for (const view of views) {
|
||||
let viewType = "unknown";
|
||||
if (!views || !Array.isArray(views) || views.length === 0) return;
|
||||
|
||||
// There will be a uncaught exception if the view is destroyed.
|
||||
try {
|
||||
viewType = view.getType();
|
||||
} catch {
|
||||
// We can ignore the view destroyed exception as viewType is only used for logging.
|
||||
}
|
||||
args = args.map(sanitizePayload);
|
||||
|
||||
// Send message to views.
|
||||
try {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to ${viewType}=${view.id}`, { args });
|
||||
view.send(channel, ...args);
|
||||
} catch (error) {
|
||||
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"`, { error: String(error) });
|
||||
}
|
||||
for (const view of views) {
|
||||
let viewType = "unknown";
|
||||
|
||||
// Send message to subFrames of views.
|
||||
for (const frameInfo of subFrames) {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
|
||||
// There will be a uncaught exception if the view is destroyed.
|
||||
try {
|
||||
viewType = view.getType();
|
||||
} catch {
|
||||
// We can ignore the view destroyed exception as viewType is only used for logging.
|
||||
}
|
||||
|
||||
try {
|
||||
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
||||
} catch (error) {
|
||||
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"'s subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { error: String(error) });
|
||||
}
|
||||
}
|
||||
// Send message to views.
|
||||
try {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to ${viewType}=${view.id}`, { args });
|
||||
view.send(channel, ...args);
|
||||
} catch (error) {
|
||||
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"`, { error });
|
||||
}
|
||||
|
||||
// Send message to subFrames of views.
|
||||
for (const frameInfo of subFrames) {
|
||||
logger.silly(`[IPC]: broadcasting "${channel}" to subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { args });
|
||||
|
||||
try {
|
||||
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
||||
} catch (error) {
|
||||
logger.error(`[IPC]: failed to send IPC message "${channel}" to view "${viewType}=${view.id}"'s subframe "frameInfo.processId"=${frameInfo.processId} "frameInfo.frameId"=${frameInfo.frameId}`, { error: String(error) });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function ipcMainOn(channel: string, listener: (event: Electron.IpcMainEvent, ...args: any[]) => any): Disposer {
|
||||
@@ -101,10 +88,6 @@ export function ipcRendererOn(channel: string, listener: (event: Electron.IpcRen
|
||||
return () => ipcRenderer.off(channel, listener);
|
||||
}
|
||||
|
||||
export function bindBroadcastHandlers() {
|
||||
ipcMainHandle(subFramesChannel, () => getSubFrames());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizing data for IPC-messaging before send.
|
||||
* Removes possible observable values to avoid exceptions like "can't clone object".
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export const windowActionHandleChannel = "window:window-action";
|
||||
export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu";
|
||||
export const windowLocationChangedChannel = "window:location-changed";
|
||||
|
||||
/**
|
||||
* The supported actions on the current window. The argument for `windowActionHandleChannel`
|
||||
*/
|
||||
export enum WindowAction {
|
||||
/**
|
||||
* Request that the current window goes back one step of browser history
|
||||
*/
|
||||
GO_BACK = "back",
|
||||
|
||||
/**
|
||||
* Request that the current window goes forward one step of browser history
|
||||
*/
|
||||
GO_FORWARD = "forward",
|
||||
|
||||
/**
|
||||
* Request that the current window is minimized
|
||||
*/
|
||||
MINIMIZE = "minimize",
|
||||
|
||||
/**
|
||||
* Request that the current window is maximized if it isn't, or unmaximized
|
||||
* if it is
|
||||
*/
|
||||
TOGGLE_MAXIMIZE = "toggle-maximize",
|
||||
|
||||
/**
|
||||
* Request that the current window is closed
|
||||
*/
|
||||
CLOSE = "close",
|
||||
}
|
||||
@@ -9,11 +9,10 @@ import { ResourceApplier } from "../../main/resource-applier";
|
||||
import type { KubernetesCluster } from "../catalog-entities";
|
||||
import logger from "../../main/logger";
|
||||
import { app } from "electron";
|
||||
import { requestMain } from "../ipc";
|
||||
import { clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler } from "../cluster-ipc";
|
||||
import { ClusterStore } from "../cluster-store/cluster-store";
|
||||
import yaml from "js-yaml";
|
||||
import { productName } from "../vars";
|
||||
import { requestKubectlApplyAll, requestKubectlDeleteAll } from "../../renderer/ipc";
|
||||
|
||||
export class ResourceStack {
|
||||
constructor(protected cluster: KubernetesCluster, protected name: string) {}
|
||||
@@ -41,7 +40,7 @@ export class ResourceStack {
|
||||
}
|
||||
|
||||
protected async applyResources(resources: string[], extraArgs?: string[]): Promise<string> {
|
||||
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid);
|
||||
const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
|
||||
|
||||
if (!clusterModel) {
|
||||
throw new Error(`cluster not found`);
|
||||
@@ -54,7 +53,7 @@ export class ResourceStack {
|
||||
if (app) {
|
||||
return await new ResourceApplier(clusterModel).kubectlApplyAll(resources, kubectlArgs);
|
||||
} else {
|
||||
const response = await requestMain(clusterKubectlApplyAllHandler, this.cluster.metadata.uid, resources, kubectlArgs);
|
||||
const response = await requestKubectlApplyAll(this.cluster.getId(), resources, kubectlArgs);
|
||||
|
||||
if (response.stderr) {
|
||||
throw new Error(response.stderr);
|
||||
@@ -65,7 +64,7 @@ export class ResourceStack {
|
||||
}
|
||||
|
||||
protected async deleteResources(resources: string[], extraArgs?: string[]): Promise<string> {
|
||||
const clusterModel = ClusterStore.getInstance().getById(this.cluster.metadata.uid);
|
||||
const clusterModel = ClusterStore.getInstance().getById(this.cluster.getId());
|
||||
|
||||
if (!clusterModel) {
|
||||
throw new Error(`cluster not found`);
|
||||
@@ -78,7 +77,7 @@ export class ResourceStack {
|
||||
if (app) {
|
||||
return await new ResourceApplier(clusterModel).kubectlDeleteAll(resources, kubectlArgs);
|
||||
} else {
|
||||
const response = await requestMain(clusterKubectlDeleteAllHandler, this.cluster.metadata.uid, resources, kubectlArgs);
|
||||
const response = await requestKubectlDeleteAll(this.cluster.getId(), resources, kubectlArgs);
|
||||
|
||||
if (response.stderr) {
|
||||
throw new Error(response.stderr);
|
||||
|
||||
Reference in new issue
Block a user