mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
moves around extension API
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4d05eff051
commit
5ff438ba42
@ -19,29 +19,21 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Lens-extensions api developer's kit
|
||||
export { LensMainExtension } from "../lens-main-extension";
|
||||
export { LensRendererExtension } from "../lens-renderer-extension";
|
||||
|
||||
// APIs
|
||||
import * as App from "./app";
|
||||
import * as EventBus from "./event-bus";
|
||||
import * as Store from "./stores";
|
||||
import * as Util from "./utils";
|
||||
import * as Interface from "../interfaces";
|
||||
import * as Main from "./main";
|
||||
import * as Renderer from "./renderer";
|
||||
import * as Catalog from "../../common/catalog";
|
||||
import * as Types from "./types";
|
||||
import * as Registrations from "./registrations";
|
||||
|
||||
export {
|
||||
App,
|
||||
EventBus,
|
||||
Main,
|
||||
Renderer,
|
||||
Catalog,
|
||||
Interface,
|
||||
Store,
|
||||
Types,
|
||||
Registrations,
|
||||
Util,
|
||||
};
|
||||
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
import { CatalogEntityRegistry as InternalCatalogEntityRegistry, CatalogCategoryRegistry as InternalCatalogCategoryRegistry, CatalogEntity, CategoryHandlerNames, CatalogHandler, EntityContextHandlers, CategoryHandlers, GlobalContextHandlers } from "../../../renderer/catalog";
|
||||
import type { CatalogCategoryRegistration } from "../../../renderer/catalog";
|
||||
|
||||
export type {
|
||||
CatalogEntity,
|
||||
} from "../../../renderer/catalog";
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
static getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||
return InternalCatalogEntityRegistry.getInstance().getItemsForApiKind<T>(apiVersion, kind);
|
||||
}
|
||||
}
|
||||
|
||||
export class CatalogCategoryRegistry {
|
||||
static add(category: CatalogCategoryRegistration) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().add(category);
|
||||
}
|
||||
|
||||
static get items() {
|
||||
return InternalCatalogCategoryRegistry.getInstance().items;
|
||||
}
|
||||
|
||||
static getForGroupKind(group: string, version: string, kind: string) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static hasForGroupKind(group: string, version: string, kind: string) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static getCategoryForEntity(data: CatalogEntity) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
|
||||
}
|
||||
|
||||
static registerHandler(apiVersion: string, kind: string, handlerName: CategoryHandlerNames, handler: CatalogHandler<typeof handlerName>) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().registerHandler(apiVersion, kind, handlerName, handler);
|
||||
}
|
||||
|
||||
static runEntityHandlersFor(entity: CatalogEntity, handlerName: "onContextMenuOpen"): ReturnType<CategoryHandlers[typeof handlerName]>;
|
||||
static runEntityHandlersFor(entity: CatalogEntity, handlerName: "onSettingsOpen"): ReturnType<CategoryHandlers[typeof handlerName]>;
|
||||
static runEntityHandlersFor(entity: CatalogEntity, handlerName: EntityContextHandlers): ReturnType<CategoryHandlers[typeof handlerName]> {
|
||||
return InternalCatalogCategoryRegistry.getInstance().runEntityHandlersFor(entity, handlerName as any);
|
||||
}
|
||||
|
||||
static runGlobalHandlersFor(reg: CatalogCategoryRegistration, handlerName: "onCatalogAddMenu"): ReturnType<CategoryHandlers[typeof handlerName]>;
|
||||
static runGlobalHandlersFor(reg: CatalogCategoryRegistration, handlerName: GlobalContextHandlers): ReturnType<CategoryHandlers[typeof handlerName]> {
|
||||
return InternalCatalogCategoryRegistry.getInstance().runGlobalHandlersFor(reg, handlerName as any);
|
||||
}
|
||||
}
|
||||
@ -22,5 +22,6 @@
|
||||
// Extensions-api types bundle (main + renderer)
|
||||
// Available for lens-extensions via NPM-package "@k8slens/extensions"
|
||||
|
||||
export * from "./core-api";
|
||||
export * from "./renderer-api";
|
||||
export * as Common from "./common-api";
|
||||
export * as Renderer from "./renderer-api";
|
||||
export * as Main from "./main-api";
|
||||
|
||||
@ -19,41 +19,42 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
import { CatalogEntityRegistry as InternalCatalogEntityRegistry, CatalogCategoryRegistry as InternalCatalogCategoryRegistry, CatalogEntity, CatalogCategoryRegistration, SpecEnhancer } from "../../../main/catalog";
|
||||
import * as internal from "../../main/catalog";
|
||||
|
||||
export type {
|
||||
CatalogEntity,
|
||||
} from "../../../main/catalog";
|
||||
} from "../../main/catalog";
|
||||
|
||||
export * from "../../main/catalog-entities";
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
static get items() {
|
||||
return InternalCatalogEntityRegistry.getInstance().items;
|
||||
return internal.CatalogEntityRegistry.getInstance().items;
|
||||
}
|
||||
}
|
||||
|
||||
export class CatalogCategoryRegistry {
|
||||
static add(category: CatalogCategoryRegistration) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().add(category);
|
||||
static add(category: internal.CatalogCategoryRegistration) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().add(category);
|
||||
}
|
||||
|
||||
static get items() {
|
||||
return InternalCatalogCategoryRegistry.getInstance().items;
|
||||
return internal.CatalogCategoryRegistry.getInstance().items;
|
||||
}
|
||||
|
||||
static getForGroupKind(group: string, version: string, kind: string) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
|
||||
return internal.CatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static hasForGroupKind(group: string, version: string, kind: string) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
|
||||
return internal.CatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static getCategoryForEntity(data: CatalogEntity) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
|
||||
static getCategoryForEntity(data: internal.CatalogEntity) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
|
||||
}
|
||||
|
||||
static registerSpecEnhancer(apiVersion: string, kind: string, handler: SpecEnhancer) {
|
||||
return InternalCatalogCategoryRegistry.getInstance().registerSpecEnhancer(apiVersion, kind, handler);
|
||||
static registerSpecEnhancer(apiVersion: string, kind: string, handler: internal.SpecEnhancer) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().registerSpecEnhancer(apiVersion, kind, handler);
|
||||
}
|
||||
}
|
||||
@ -19,5 +19,10 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "./registrations";
|
||||
export * from "./catalog";
|
||||
import * as Catalog from "./catalog";
|
||||
|
||||
export { LensMainExtension } from "../lens-main-extension";
|
||||
|
||||
export {
|
||||
Catalog,
|
||||
};
|
||||
74
src/extensions/renderer-api/catalog.ts
Normal file
74
src/extensions/renderer-api/catalog.ts
Normal file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OpenLens Authors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import * as internal from "../../renderer/catalog";
|
||||
|
||||
export type {
|
||||
CatalogEntity,
|
||||
CatalogCategoryRegistration,
|
||||
} from "../../renderer/catalog";
|
||||
|
||||
export type {
|
||||
KubernetesCluster,
|
||||
} from "../../renderer/catalog-entities";
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
static getItemsForApiKind<T extends internal.CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||
return internal.CatalogEntityRegistry.getInstance().getItemsForApiKind<T>(apiVersion, kind);
|
||||
}
|
||||
}
|
||||
|
||||
export class CatalogCategoryRegistry {
|
||||
static add(category: internal.CatalogCategoryRegistration) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().add(category);
|
||||
}
|
||||
|
||||
static get items() {
|
||||
return internal.CatalogCategoryRegistry.getInstance().items;
|
||||
}
|
||||
|
||||
static getForGroupKind(group: string, version: string, kind: string) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().getForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static hasForGroupKind(group: string, version: string, kind: string) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().hasForGroupKind(group, version, kind);
|
||||
}
|
||||
|
||||
static getCategoryForEntity(data: internal.CatalogEntity) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().getCategoryForEntity(data);
|
||||
}
|
||||
|
||||
static registerHandler(apiVersion: string, kind: string, handlerName: internal.CategoryHandlerNames, handler: internal.CatalogHandler<typeof handlerName>) {
|
||||
return internal.CatalogCategoryRegistry.getInstance().registerHandler(apiVersion, kind, handlerName, handler);
|
||||
}
|
||||
|
||||
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: "onContextMenuOpen"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
|
||||
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: "onSettingsOpen"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
|
||||
static runEntityHandlersFor(entity: internal.CatalogEntity, handlerName: internal.EntityContextHandlers): ReturnType<internal.CategoryHandlers[typeof handlerName]> {
|
||||
return internal.CatalogCategoryRegistry.getInstance().runEntityHandlersFor(entity, handlerName as any);
|
||||
}
|
||||
|
||||
static runGlobalHandlersFor(reg: internal.CatalogCategoryRegistration, handlerName: "onCatalogAddMenu"): ReturnType<internal.CategoryHandlers[typeof handlerName]>;
|
||||
static runGlobalHandlersFor(reg: internal.CatalogCategoryRegistration, handlerName: internal.GlobalContextHandlers): ReturnType<internal.CategoryHandlers[typeof handlerName]> {
|
||||
return internal.CatalogCategoryRegistry.getInstance().runGlobalHandlersFor(reg, handlerName as any);
|
||||
}
|
||||
}
|
||||
@ -20,16 +20,19 @@
|
||||
*/
|
||||
|
||||
// Lens-extensions apis, required in renderer process runtime
|
||||
export { LensRendererExtension } from "../lens-renderer-extension";
|
||||
|
||||
// APIs
|
||||
import * as Component from "./components";
|
||||
import * as K8sApi from "./k8s-api";
|
||||
import * as Navigation from "./navigation";
|
||||
import * as Theme from "./theming";
|
||||
import * as Catalog from "./catalog";
|
||||
|
||||
export {
|
||||
Component,
|
||||
K8sApi,
|
||||
Navigation,
|
||||
Theme,
|
||||
Catalog,
|
||||
};
|
||||
|
||||
@ -19,4 +19,10 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * as Catalog from "./catalog";
|
||||
import * as KubernetesCluster from "./kubernetes-cluster";
|
||||
import * as WebLink from "./web-link";
|
||||
|
||||
export {
|
||||
KubernetesCluster,
|
||||
WebLink,
|
||||
};
|
||||
@ -19,4 +19,15 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * as Catalog from "./catalog";
|
||||
import type { CatalogEntityMetadata } from "../../common/catalog";
|
||||
import type { KubernetesClusterSpec } from "../../common/catalog-entities";
|
||||
import type { CatalogEntity } from "../catalog/catalog-entity";
|
||||
|
||||
export function v1alpha1(metadata: CatalogEntityMetadata, spec: KubernetesClusterSpec): CatalogEntity<CatalogEntityMetadata, KubernetesClusterSpec> {
|
||||
return {
|
||||
apiVersion: "entity.k8slens.dev/v1alpha1",
|
||||
kind: "KubernetesCluster",
|
||||
metadata,
|
||||
spec,
|
||||
};
|
||||
}
|
||||
@ -19,4 +19,15 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "../../common/catalog/catalog-entity";
|
||||
import type { CatalogEntityMetadata } from "../../common/catalog";
|
||||
import type { WebLinkSpec } from "../../common/catalog-entities";
|
||||
import type { CatalogEntity } from "../catalog";
|
||||
|
||||
export function v1alpha1(metadata: CatalogEntityMetadata, spec: WebLinkSpec): CatalogEntity<CatalogEntityMetadata, WebLinkSpec> {
|
||||
return {
|
||||
apiVersion: "entity.k8slens.dev/v1alpha1",
|
||||
kind: "WebLink",
|
||||
metadata,
|
||||
spec,
|
||||
};
|
||||
}
|
||||
@ -31,6 +31,7 @@ import { noop, Singleton } from "../common/utils";
|
||||
import { CatalogCategoryRegistry, CatalogEntity } from "./catalog";
|
||||
import type { KubernetesClusterSpec } from "../common/catalog-entities/kubernetes-cluster";
|
||||
import type { CatalogEntityMetadata } from "../common/catalog";
|
||||
import { KubernetesCluster } from "./catalog-entities";
|
||||
|
||||
export class ClusterManager extends Singleton {
|
||||
protected clusters = observable.map<string, Cluster>();
|
||||
@ -155,10 +156,8 @@ export class ClusterManager extends Singleton {
|
||||
}
|
||||
|
||||
export function catalogEntityFromCluster(cluster: ClusterModel): CatalogEntity<CatalogEntityMetadata, KubernetesClusterSpec> {
|
||||
return {
|
||||
apiVersion: "entity.k8slens.dev/v1alpha1",
|
||||
kind: "KubernetesCluster",
|
||||
metadata: {
|
||||
return KubernetesCluster.v1alpha1(
|
||||
{
|
||||
uid: cluster.id,
|
||||
name: cluster.contextName,
|
||||
source: "local",
|
||||
@ -166,9 +165,9 @@ export function catalogEntityFromCluster(cluster: ClusterModel): CatalogEntity<C
|
||||
distro: cluster.metadata.distribution?.toString() || "unknown",
|
||||
}
|
||||
},
|
||||
spec: {
|
||||
{
|
||||
kubeconfigPath: cluster.kubeConfigPath,
|
||||
kubeconfigContext: cluster.contextName
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
import "../common/system-ca";
|
||||
import "../common/prometheus-providers";
|
||||
import * as Mobx from "mobx";
|
||||
import * as LensExtensionsCoreApi from "../extensions/core-api";
|
||||
import * as LensExtensionsCoreApi from "../extensions/common-api";
|
||||
import { app, autoUpdater, ipcMain, dialog, powerMonitor } from "electron";
|
||||
import { appName, isMac, productName } from "../common/vars";
|
||||
import path from "path";
|
||||
|
||||
@ -24,7 +24,7 @@ import * as uuid from "uuid";
|
||||
import { broadcastMessage } from "../../../common/ipc";
|
||||
import { ProtocolHandlerExtension, ProtocolHandlerInternal } from "../../../common/protocol-handler";
|
||||
import { noop } from "../../../common/utils";
|
||||
import { LensMainExtension } from "../../../extensions/core-api";
|
||||
import { LensMainExtension } from "../../../extensions/main-api";
|
||||
import { ExtensionLoader } from "../../../extensions/extension-loader";
|
||||
import { ExtensionsStore } from "../../../extensions/extensions-store";
|
||||
import { LensProtocolRouterMain } from "../router";
|
||||
|
||||
@ -26,7 +26,7 @@ import * as Mobx from "mobx";
|
||||
import * as MobxReact from "mobx-react";
|
||||
import * as ReactRouter from "react-router";
|
||||
import * as ReactRouterDom from "react-router-dom";
|
||||
import * as LensExtensionsCoreApi from "../extensions/core-api";
|
||||
import * as LensExtensionsCoreApi from "../extensions/common-api";
|
||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||
import { render, unmountComponentAtNode } from "react-dom";
|
||||
import { delay } from "../common/utils";
|
||||
@ -48,11 +48,6 @@ import configurePackages from "../common/configure-packages";
|
||||
|
||||
configurePackages();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
async function attachChromeDebugger() {
|
||||
if (isDevelopment) {
|
||||
await delay(1000);
|
||||
|
||||
@ -37,7 +37,7 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
||||
return requestMain(clusterDisconnectHandler, this.metadata.uid, false);
|
||||
}
|
||||
|
||||
onRun = (context: CatalogEntityActionContext) => {
|
||||
onRun(context: CatalogEntityActionContext) {
|
||||
context.navigate(`/cluster/${this.metadata.uid}`);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||
public readonly kind = "WebLink";
|
||||
|
||||
onRun = () => {
|
||||
onRun() {
|
||||
window.open(this.spec.url, "_blank");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,5 +118,7 @@ export class CatalogEntity<
|
||||
this.name = this.metadata.name;
|
||||
}
|
||||
|
||||
onRun?(context: CatalogEntityActionContext): void;
|
||||
onRun(context: CatalogEntityActionContext): void {
|
||||
void context;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user