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 2021-09-08 12:14:34 +03:00
parent 8a8edd0450
commit 54c8f29df3
5 changed files with 17 additions and 15 deletions

View File

@ -20,7 +20,6 @@
*/ */
export const dialogShowOpenDialogHandler = "dialog:show-open-dialog"; export const dialogShowOpenDialogHandler = "dialog:show-open-dialog";
export const catalogBroadcastHandler = "catalog:broadcast-items";
export * from "./ipc"; export * from "./ipc";
export * from "./invalid-kubeconfig"; export * from "./invalid-kubeconfig";

View File

@ -28,13 +28,13 @@ import { debounce } from "lodash";
import type { CatalogEntity } from "../common/catalog"; import type { CatalogEntity } from "../common/catalog";
export const catalogBroadcaster = debounce((items: CatalogEntity[]) => { const broadcaster = debounce((items: CatalogEntity[]) => {
broadcastMessage("catalog:items", items); broadcastMessage("catalog:items", items);
}, 1_000, { leading: true, trailing: true }); }, 1_000, { leading: true, trailing: true });
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) { export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
return reaction(() => toJS(catalog.items), (items) => { return reaction(() => toJS(catalog.items), (items) => {
catalogBroadcaster(items); broadcaster(items);
}, { }, {
fireImmediately: true, fireImmediately: true,
}); });

View File

@ -26,9 +26,9 @@ import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHand
import { ClusterStore } from "../../common/cluster-store"; import { ClusterStore } from "../../common/cluster-store";
import type { ClusterId } from "../../common/cluster-types"; import type { ClusterId } from "../../common/cluster-types";
import { appEventBus } from "../../common/event-bus"; import { appEventBus } from "../../common/event-bus";
import { catalogBroadcastHandler, dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc"; import { dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc";
import { catalogEntityRegistry } from "../catalog"; import { catalogEntityRegistry } from "../catalog";
import { catalogBroadcaster } from "../catalog-pusher"; import { pushCatalogToRenderer } from "../catalog-pusher";
import { ClusterManager } from "../cluster-manager"; import { ClusterManager } from "../cluster-manager";
import { bundledKubectlPath } from "../kubectl"; import { bundledKubectlPath } from "../kubectl";
import logger from "../logger"; import logger from "../logger";
@ -49,6 +49,8 @@ export function initIpcMainHandlers() {
if (cluster) { if (cluster) {
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId }); clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
cluster.pushState(); cluster.pushState();
pushCatalogToRenderer(catalogEntityRegistry);
} }
}); });
@ -146,9 +148,4 @@ export function initIpcMainHandlers() {
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts); return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
}); });
ipcMainHandle(catalogBroadcastHandler, async () => {
catalogBroadcaster(catalogEntityRegistry.items);
});
} }

View File

@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { observable, makeObservable } from "mobx"; import { observable, makeObservable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { Redirect, Route, Router, Switch } from "react-router"; import { Redirect, Route, Router, Switch } from "react-router";
import { history } from "../navigation"; import { history } from "../navigation";
@ -37,7 +37,7 @@ import { webFrame } from "electron";
import { ClusterPageRegistry, getExtensionPageUrl } from "../../extensions/registries/page-registry"; import { ClusterPageRegistry, getExtensionPageUrl } from "../../extensions/registries/page-registry";
import { ExtensionLoader } from "../../extensions/extension-loader"; import { ExtensionLoader } from "../../extensions/extension-loader";
import { appEventBus } from "../../common/event-bus"; import { appEventBus } from "../../common/event-bus";
import { catalogBroadcastHandler, 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"; import { clusterSetFrameIdHandler } from "../../common/cluster-ipc";
import { ClusterPageMenuRegistration, ClusterPageMenuRegistry } from "../../extensions/registries"; import { ClusterPageMenuRegistration, ClusterPageMenuRegistry } from "../../extensions/registries";
@ -92,12 +92,19 @@ export class App extends React.Component {
logger.info(`[APP]: Init dashboard, clusterId=${App.clusterId}, frameId=${frameId}`); logger.info(`[APP]: Init dashboard, clusterId=${App.clusterId}, frameId=${frameId}`);
await Terminal.preloadFonts(); await Terminal.preloadFonts();
await requestMain(clusterSetFrameIdHandler, App.clusterId); await requestMain(clusterSetFrameIdHandler, App.clusterId);
await requestMain(catalogBroadcastHandler);
const cluster = ClusterStore.getInstance().getById(App.clusterId); const cluster = ClusterStore.getInstance().getById(App.clusterId);
await cluster.whenReady; // cluster.activate() is done at this point await cluster.whenReady; // cluster.activate() is done at this point
const activeEntityDisposer = reaction(() => catalogEntityRegistry.getById(App.clusterId), (entity) => {
if (!entity) {
return;
}
catalogEntityRegistry.activeEntity = entity;
activeEntityDisposer();
}, {fireImmediately: true});
ExtensionLoader.getInstance().loadOnClusterRenderer(); ExtensionLoader.getInstance().loadOnClusterRenderer();
setTimeout(() => { setTimeout(() => {
appEventBus.emit({ appEventBus.emit({

View File

@ -40,7 +40,6 @@ import { SidebarItem } from "./sidebar-item";
import { Apps } from "../+apps"; import { Apps } from "../+apps";
import * as routes from "../../../common/routes"; import * as routes from "../../../common/routes";
import { Config } from "../+config"; import { Config } from "../+config";
import { App } from "../app";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
interface Props { interface Props {
@ -179,7 +178,7 @@ export class Sidebar extends React.Component<Props> {
} }
get clusterEntity() { get clusterEntity() {
return catalogEntityRegistry.getById(App.clusterId); return catalogEntityRegistry.activeEntity;
} }
render() { render() {