mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
base branch merge fixes / clean up
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
8e2740b2ed
commit
59ca12ff31
@ -1,4 +1,4 @@
|
||||
import { LensMainExtension, Registry } from "@lens/extensions";
|
||||
import { LensMainExtension, Registry } from "@k8slens/extensions";
|
||||
import { supportPageURL } from "./src/support.route";
|
||||
|
||||
export default class SupportPageMainExtension extends LensMainExtension {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { LensRendererExtension, Registry } from "@lens/ui-extensions";
|
||||
import { LensRendererExtension, Registry } from "@k8slens/extensions";
|
||||
import { Support } from "./src/support";
|
||||
import { supportPageRoute, supportPageURL } from "./src/support.route";
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
import React from "react"
|
||||
import { observer } from "mobx-react"
|
||||
import { CommonVars, Component } from "@lens/ui-extensions";
|
||||
import { CommonVars, Component } from "@k8slens/extensions";
|
||||
|
||||
@observer
|
||||
export class Support extends React.Component {
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
},
|
||||
"include": [
|
||||
"renderer.ts",
|
||||
"../../types/",
|
||||
"../../src/extensions/npm/**/*.d.ts",
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
|
||||
@ -3,6 +3,13 @@ import path from "path"
|
||||
const outputPath = path.resolve(__dirname, 'dist');
|
||||
|
||||
// TODO: figure out how to share base TS and Webpack configs from Lens (npm, filesystem, etc?)
|
||||
const lensExternals = {
|
||||
"@k8slens/extensions": "var global.LensExtensions",
|
||||
"react": "var global.React",
|
||||
"mobx": "var global.Mobx",
|
||||
"mobx-react": "var global.MobxReact",
|
||||
};
|
||||
|
||||
export default [
|
||||
{
|
||||
entry: './main.ts',
|
||||
@ -19,14 +26,10 @@ export default [
|
||||
],
|
||||
},
|
||||
externals: [
|
||||
{
|
||||
"@lens/extensions": "var global.LensExtensions",
|
||||
"react": "var global.React",
|
||||
"mobx": "var global.Mobx"
|
||||
}
|
||||
lensExternals,
|
||||
],
|
||||
resolve: {
|
||||
extensions: [ '.tsx', '.ts', '.js' ],
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
},
|
||||
output: {
|
||||
libraryTarget: "commonjs2",
|
||||
@ -50,15 +53,10 @@ export default [
|
||||
],
|
||||
},
|
||||
externals: [
|
||||
{
|
||||
"@lens/ui-extensions": "var global.LensExtensions",
|
||||
"@lens/extensions": "var global.LensMainExtensions",
|
||||
"react": "var global.React",
|
||||
"mobx": "var global.Mobx"
|
||||
}
|
||||
lensExternals,
|
||||
],
|
||||
resolve: {
|
||||
extensions: [ '.tsx', '.ts', '.js' ],
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
},
|
||||
output: {
|
||||
libraryTarget: "commonjs2",
|
||||
|
||||
@ -9,8 +9,8 @@
|
||||
"styles": []
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"dev": "npm run build --watch"
|
||||
"build": "webpack -p",
|
||||
"dev": "webpack --watch"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
|
||||
@ -26,5 +26,5 @@
|
||||
"renderer.ts",
|
||||
"../../src/extensions/npm/**/*.d.ts",
|
||||
"src/**/*"
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
18
src/extensions/core-api/index.ts
Normal file
18
src/extensions/core-api/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// Lens-extensions api developer's kit
|
||||
export * from "../lens-main-extension"
|
||||
export * from "../lens-renderer-extension"
|
||||
|
||||
// APIs
|
||||
import * as EventBus from "./event-bus"
|
||||
import * as Store from "./stores"
|
||||
import * as Util from "./utils"
|
||||
import * as Registry from "../registries"
|
||||
import * as CommonVars from "../../common/vars";
|
||||
|
||||
export {
|
||||
EventBus,
|
||||
Store,
|
||||
Util,
|
||||
Registry,
|
||||
CommonVars,
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
// Lens-extensions api developer's kit
|
||||
export type { LensExtensionRuntimeEnv } from "./lens-runtime";
|
||||
export * from "./lens-main-extension"
|
||||
export * from "./lens-renderer-extension"
|
||||
|
||||
// APIs
|
||||
import * as EventBus from "./core-api/event-bus"
|
||||
import * as Store from "./core-api/stores"
|
||||
import * as Util from "./core-api/utils"
|
||||
import * as Registry from "./core-api/registries"
|
||||
|
||||
export {
|
||||
EventBus,
|
||||
Registry,
|
||||
Store,
|
||||
Util
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import React from "react";
|
||||
import { cssNames } from "../renderer/utils";
|
||||
import { TabLayout } from "../renderer/components/layout/tab-layout";
|
||||
import { PageRegistration } from "./page-registry"
|
||||
import { PageRegistration } from "./registries/page-registry"
|
||||
|
||||
export class DynamicPage extends React.Component<{ page: PageRegistration }> {
|
||||
render() {
|
||||
|
||||
@ -1,2 +1,4 @@
|
||||
export * from "./core-extension-api"
|
||||
export * from "./renderer-extension-api"
|
||||
// Extension-api types generation bundle (used by rollup.js)
|
||||
|
||||
export * from "./core-api"
|
||||
export * from "./renderer-api"
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
import type { ExtensionId, LensExtension, ExtensionManifest, ExtensionModel } from "./lens-extension"
|
||||
import type { ExtensionId, ExtensionManifest, ExtensionModel, LensExtension } from "./lens-extension"
|
||||
import type { LensMainExtension } from "./lens-main-extension"
|
||||
import type { LensRendererExtension } from "./lens-renderer-extension"
|
||||
import type { LensExtensionMainRuntimeEnv } from "./lens-runtime"
|
||||
import type { LensExtensionRendererRuntimeEnv } from "./lens-renderer-runtime"
|
||||
import path from "path"
|
||||
import { broadcastIpc } from "../common/ipc"
|
||||
import { observable, reaction, toJS, } from "mobx"
|
||||
import logger from "../main/logger"
|
||||
import { app, remote, ipcRenderer } from "electron"
|
||||
import { pageRegistry } from "./page-registry";
|
||||
import { appPreferenceRegistry } from "./app-preference-registry"
|
||||
import { menuRegistry } from "./menu-registry";
|
||||
import { statusBarRegistry } from "./status-bar-registry";
|
||||
import { app, ipcRenderer, remote } from "electron"
|
||||
import { appPreferenceRegistry, menuRegistry, pageRegistry, statusBarRegistry } from "./registries";
|
||||
|
||||
export interface InstalledExtension extends ExtensionModel {
|
||||
manifestPath: string;
|
||||
@ -39,32 +34,32 @@ export class ExtensionLoader {
|
||||
}
|
||||
}
|
||||
|
||||
loadOnClusterRenderer(getLensRuntimeEnv: () => LensExtensionRendererRuntimeEnv) {
|
||||
loadOnClusterRenderer() {
|
||||
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer')
|
||||
this.autoloadExtensions(getLensRuntimeEnv, (instance: LensRendererExtension) => {
|
||||
this.autoloadExtensions((instance: LensRendererExtension) => {
|
||||
instance.registerPages(pageRegistry)
|
||||
})
|
||||
}
|
||||
|
||||
loadOnMainRenderer(getLensRuntimeEnv: () => LensExtensionRendererRuntimeEnv) {
|
||||
loadOnMainRenderer() {
|
||||
logger.info('[EXTENSIONS-LOADER]: load on main renderer')
|
||||
this.autoloadExtensions(getLensRuntimeEnv, (instance: LensRendererExtension) => {
|
||||
this.autoloadExtensions((instance: LensRendererExtension) => {
|
||||
instance.registerPages(pageRegistry)
|
||||
instance.registerAppPreferences(appPreferenceRegistry)
|
||||
})
|
||||
}
|
||||
|
||||
loadOnMain(getLensRuntimeEnv: () => LensExtensionMainRuntimeEnv) {
|
||||
loadOnMain() {
|
||||
logger.info('[EXTENSIONS-LOADER]: load on main')
|
||||
this.autoloadExtensions(getLensRuntimeEnv, (instance: LensMainExtension) => {
|
||||
this.autoloadExtensions((instance: LensMainExtension) => {
|
||||
instance.registerAppMenus(menuRegistry);
|
||||
instance.registerStatusBarIcon(statusBarRegistry);
|
||||
})
|
||||
}
|
||||
|
||||
protected autoloadExtensions(getLensRuntimeEnv: () => object, callback: (instance: LensExtension) => void) {
|
||||
protected autoloadExtensions(callback: (instance: LensExtension) => void) {
|
||||
return reaction(() => this.extensions.toJS(), (installedExtensions) => {
|
||||
for(const [id, ext] of installedExtensions) {
|
||||
for (const [id, ext] of installedExtensions) {
|
||||
let instance = this.instances.get(ext.manifestPath)
|
||||
if (!instance) {
|
||||
const extensionModule = this.requireExtension(ext)
|
||||
@ -73,7 +68,7 @@ export class ExtensionLoader {
|
||||
}
|
||||
const LensExtensionClass = extensionModule.default;
|
||||
instance = new LensExtensionClass({ ...ext.manifest, manifestPath: ext.manifestPath, id: ext.manifestPath }, ext.manifest);
|
||||
instance.enable(getLensRuntimeEnv())
|
||||
instance.enable();
|
||||
callback(instance)
|
||||
this.instances.set(ext.id, instance)
|
||||
}
|
||||
@ -109,7 +104,9 @@ export class ExtensionLoader {
|
||||
const extension = this.getById(id);
|
||||
if (extension) {
|
||||
const instance = this.instances.get(extension.id)
|
||||
if (instance) { await instance.disable() }
|
||||
if (instance) {
|
||||
await instance.disable()
|
||||
}
|
||||
this.extensions.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,6 @@ export class LensExtension implements ExtensionModel {
|
||||
@observable manifest: ExtensionManifest;
|
||||
@observable manifestPath: string;
|
||||
@observable isEnabled = false;
|
||||
@observable.ref runtime: any;
|
||||
|
||||
constructor(model: ExtensionModel, manifest: ExtensionManifest) {
|
||||
this.importModel(model, manifest);
|
||||
@ -55,9 +54,8 @@ export class LensExtension implements ExtensionModel {
|
||||
// mock
|
||||
}
|
||||
|
||||
async enable(runtime: any) {
|
||||
async enable() {
|
||||
this.isEnabled = true;
|
||||
this.runtime = runtime;
|
||||
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
|
||||
this.onActivate();
|
||||
}
|
||||
@ -65,7 +63,6 @@ export class LensExtension implements ExtensionModel {
|
||||
async disable() {
|
||||
this.onDeactivate();
|
||||
this.isEnabled = false;
|
||||
this.runtime = null;
|
||||
this.disposers.forEach(cleanUp => cleanUp());
|
||||
this.disposers.length = 0;
|
||||
logger.info(`[EXTENSION]: disabled ${this.name}@${this.version}`);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { LensExtension } from "./lens-extension"
|
||||
import type { MenuRegistry } from "./menu-registry";
|
||||
import type { StatusBarRegistry } from "./status-bar-registry";
|
||||
import type { MenuRegistry } from "./registries/menu-registry";
|
||||
import type { StatusBarRegistry } from "./registries/status-bar-registry";
|
||||
|
||||
export class LensMainExtension extends LensExtension {
|
||||
registerAppMenus(registry: MenuRegistry) {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { LensExtension } from "./lens-extension"
|
||||
import type { PageRegistry } from "./page-registry"
|
||||
import type { AppPreferenceRegistry } from "./app-preference-registry";
|
||||
import type { PageRegistry } from "./registries/page-registry"
|
||||
import type { AppPreferenceRegistry } from "./registries/app-preference-registry";
|
||||
|
||||
export class LensRendererExtension extends LensExtension {
|
||||
|
||||
registerPages(registry: PageRegistry) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
// Lens extension runtime params available to extensions after activation
|
||||
|
||||
import logger from "../main/logger";
|
||||
|
||||
export interface LensExtensionMainRuntimeEnv {
|
||||
logger: typeof logger;
|
||||
}
|
||||
|
||||
export function getLensRuntime(): LensExtensionMainRuntimeEnv {
|
||||
return {
|
||||
logger
|
||||
}
|
||||
}
|
||||
4
src/extensions/registries/index.ts
Normal file
4
src/extensions/registries/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from "./page-registry"
|
||||
export * from "./menu-registry"
|
||||
export * from "./app-preference-registry"
|
||||
export * from "./status-bar-registry"
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { observable } from "mobx";
|
||||
import { MenuItemConstructorOptions } from "electron";
|
||||
import type { MenuTopId } from "../main/menu";
|
||||
import type { MenuTopId } from "../../main/menu";
|
||||
|
||||
export interface MenuRegistration extends MenuItemConstructorOptions {
|
||||
parentId?: MenuTopId;
|
||||
@ -1,11 +1,11 @@
|
||||
// Extensions-api -> Dynamic pages
|
||||
|
||||
import type React from "react";
|
||||
import type { RouteProps } from "react-router";
|
||||
import type { IconProps } from "../../renderer/components/icon";
|
||||
import type { IClassName } from "../../renderer/utils";
|
||||
import type { TabRoute } from "../../renderer/components/layout/tab-layout";
|
||||
import { computed, observable } from "mobx";
|
||||
import React from "react";
|
||||
import { RouteProps } from "react-router";
|
||||
import { IconProps } from "../renderer/components/icon";
|
||||
import { IClassName } from "../renderer/utils";
|
||||
import { TabRoute } from "../renderer/components/layout/tab-layout";
|
||||
|
||||
export enum PageRegistryType {
|
||||
GLOBAL = "lens-scope",
|
||||
@ -40,9 +40,7 @@ export class PageRegistry {
|
||||
// fixme: validate route paths to avoid collisions
|
||||
add(pageInit: PageRegistration) {
|
||||
this.pages.push(pageInit);
|
||||
return () => {
|
||||
this.pages.remove(pageInit); // works because of {deep: false}
|
||||
};
|
||||
return () => this.pages.remove(pageInit); // works because of {deep: false};
|
||||
}
|
||||
}
|
||||
|
||||
12
src/extensions/renderer-api/index.ts
Normal file
12
src/extensions/renderer-api/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// Lens-extensions apis, required in renderer process runtime
|
||||
|
||||
// APIs
|
||||
import * as Component from "./components"
|
||||
import * as K8sApi from "./k8s-api"
|
||||
import * as Navigation from "./navigation"
|
||||
|
||||
export {
|
||||
Component,
|
||||
K8sApi,
|
||||
Navigation,
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
// APIs
|
||||
import * as Component from "./renderer-api/components"
|
||||
import * as K8sApi from "./renderer-api/k8s-api"
|
||||
import * as Navigation from "./renderer-api/navigation"
|
||||
|
||||
export {
|
||||
Component,
|
||||
K8sApi,
|
||||
Navigation,
|
||||
}
|
||||
@ -17,10 +17,9 @@ import { clusterStore } from "../common/cluster-store"
|
||||
import { userStore } from "../common/user-store";
|
||||
import { workspaceStore } from "../common/workspace-store";
|
||||
import { appEventBus } from "../common/event-bus"
|
||||
import * as LensExtensions from "../extensions/core-extension-api";
|
||||
import * as LensExtensions from "../extensions/core-api";
|
||||
import { extensionManager } from "../extensions/extension-manager";
|
||||
import { extensionLoader } from "../extensions/extension-loader";
|
||||
import { getLensRuntime } from "../extensions/lens-runtime";
|
||||
import logger from "./logger"
|
||||
import * as Mobx from "mobx"
|
||||
|
||||
@ -85,7 +84,7 @@ async function main() {
|
||||
// create window manager and open app
|
||||
windowManager = new WindowManager(proxyPort);
|
||||
|
||||
extensionLoader.loadOnMain(getLensRuntime)
|
||||
extensionLoader.loadOnMain()
|
||||
extensionLoader.extensions.replace(await extensionManager.load())
|
||||
extensionLoader.broadcastExtensions()
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.r
|
||||
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
||||
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route";
|
||||
import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route";
|
||||
import { menuRegistry } from "../extensions/menu-registry";
|
||||
import { menuRegistry } from "../extensions/registries/menu-registry";
|
||||
import logger from "./logger";
|
||||
|
||||
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import "./components/app.scss"
|
||||
|
||||
import React from "react";
|
||||
import * as Mobx from "mobx"
|
||||
import * as MobxReact from "mobx-react"
|
||||
|
||||
@ -16,7 +16,7 @@ import { Badge } from "../badge";
|
||||
import { themeStore } from "../../theme.store";
|
||||
import { Tooltip } from "../tooltip";
|
||||
import { KubectlBinaries } from "./kubectl-binaries";
|
||||
import { appPreferenceRegistry } from "../../../extensions/app-preference-registry";
|
||||
import { appPreferenceRegistry } from "../../../extensions/registries/app-preference-registry";
|
||||
import { PageLayout } from "../layout/page-layout";
|
||||
|
||||
@observer
|
||||
|
||||
@ -35,10 +35,9 @@ import { getHostedCluster, getHostedClusterId } from "../../common/cluster-store
|
||||
import logger from "../../main/logger";
|
||||
import { clusterIpc } from "../../common/cluster-ipc";
|
||||
import { webFrame } from "electron";
|
||||
import { pageRegistry } from "../../extensions/page-registry";
|
||||
import { pageRegistry } from "../../extensions/registries/page-registry";
|
||||
import { DynamicPage } from "../../extensions/dynamic-page";
|
||||
import { extensionLoader } from "../../extensions/extension-loader";
|
||||
import { getLensRuntimeRenderer } from "../../extensions/lens-renderer-runtime";
|
||||
import { appEventBus } from "../../common/event-bus"
|
||||
|
||||
@observer
|
||||
@ -51,7 +50,7 @@ export class App extends React.Component {
|
||||
|
||||
await clusterIpc.setFrameId.invokeFromRenderer(clusterId, frameId);
|
||||
await getHostedCluster().whenReady; // cluster.activate() is done at this point
|
||||
extensionLoader.loadOnClusterRenderer(getLensRuntimeRenderer)
|
||||
extensionLoader.loadOnClusterRenderer();
|
||||
appEventBus.emit({name: "cluster", action: "open", params: {
|
||||
clusterId: clusterId
|
||||
}})
|
||||
|
||||
@ -14,7 +14,7 @@ import { ClusterSettings, clusterSettingsRoute } from "../+cluster-settings";
|
||||
import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
||||
import { clusterStore } from "../../../common/cluster-store";
|
||||
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
||||
import { pageRegistry } from "../../../extensions/page-registry";
|
||||
import { pageRegistry } from "../../../extensions/registries/page-registry";
|
||||
|
||||
@observer
|
||||
export class ClusterManager extends React.Component {
|
||||
|
||||
@ -22,7 +22,7 @@ import { ConfirmDialog } from "../confirm-dialog";
|
||||
import { clusterIpc } from "../../../common/cluster-ipc";
|
||||
import { clusterViewURL } from "./cluster-view.route";
|
||||
import { DragDropContext, Draggable, DraggableProvided, Droppable, DroppableProvided, DropResult } from "react-beautiful-dnd";
|
||||
import { pageRegistry } from "../../../extensions/page-registry";
|
||||
import { pageRegistry } from "../../../extensions/registries/page-registry";
|
||||
|
||||
interface Props {
|
||||
className?: IClassName;
|
||||
|
||||
@ -28,7 +28,7 @@ import { CrdList, crdResourcesRoute, crdRoute, crdURL } from "../+custom-resourc
|
||||
import { CustomResources } from "../+custom-resources/custom-resources";
|
||||
import { navigation } from "../../navigation";
|
||||
import { isAllowedResource } from "../../../common/rbac"
|
||||
import { pageRegistry } from "../../../extensions/page-registry";
|
||||
import { pageRegistry } from "../../../extensions/registries/page-registry";
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextValue>({ pinned: false });
|
||||
type SidebarContextValue = {
|
||||
|
||||
@ -12,12 +12,11 @@ import { WhatsNew, whatsNewRoute } from "./components/+whats-new";
|
||||
import { Notifications } from "./components/notifications";
|
||||
import { ConfirmDialog } from "./components/confirm-dialog";
|
||||
import { extensionLoader } from "../extensions/extension-loader";
|
||||
import { getLensRuntimeRenderer } from "../extensions/lens-renderer-runtime";
|
||||
|
||||
@observer
|
||||
export class LensApp extends React.Component {
|
||||
static async init() {
|
||||
extensionLoader.loadOnMainRenderer(getLensRuntimeRenderer)
|
||||
extensionLoader.loadOnMainRenderer();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user