mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
simplify
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
8a8edd0450
commit
54c8f29df3
@ -20,7 +20,6 @@
|
||||
*/
|
||||
|
||||
export const dialogShowOpenDialogHandler = "dialog:show-open-dialog";
|
||||
export const catalogBroadcastHandler = "catalog:broadcast-items";
|
||||
|
||||
export * from "./ipc";
|
||||
export * from "./invalid-kubeconfig";
|
||||
|
||||
@ -28,13 +28,13 @@ import { debounce } from "lodash";
|
||||
import type { CatalogEntity } from "../common/catalog";
|
||||
|
||||
|
||||
export const catalogBroadcaster = debounce((items: CatalogEntity[]) => {
|
||||
const broadcaster = debounce((items: CatalogEntity[]) => {
|
||||
broadcastMessage("catalog:items", items);
|
||||
}, 1_000, { leading: true, trailing: true });
|
||||
|
||||
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
||||
return reaction(() => toJS(catalog.items), (items) => {
|
||||
catalogBroadcaster(items);
|
||||
broadcaster(items);
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
});
|
||||
|
||||
@ -26,9 +26,9 @@ import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHand
|
||||
import { ClusterStore } from "../../common/cluster-store";
|
||||
import type { ClusterId } from "../../common/cluster-types";
|
||||
import { appEventBus } from "../../common/event-bus";
|
||||
import { catalogBroadcastHandler, dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc";
|
||||
import { dialogShowOpenDialogHandler, ipcMainHandle } from "../../common/ipc";
|
||||
import { catalogEntityRegistry } from "../catalog";
|
||||
import { catalogBroadcaster } from "../catalog-pusher";
|
||||
import { pushCatalogToRenderer } from "../catalog-pusher";
|
||||
import { ClusterManager } from "../cluster-manager";
|
||||
import { bundledKubectlPath } from "../kubectl";
|
||||
import logger from "../logger";
|
||||
@ -49,6 +49,8 @@ export function initIpcMainHandlers() {
|
||||
if (cluster) {
|
||||
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
|
||||
cluster.pushState();
|
||||
|
||||
pushCatalogToRenderer(catalogEntityRegistry);
|
||||
}
|
||||
});
|
||||
|
||||
@ -146,9 +148,4 @@ export function initIpcMainHandlers() {
|
||||
|
||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), dialogOpts);
|
||||
});
|
||||
|
||||
|
||||
ipcMainHandle(catalogBroadcastHandler, async () => {
|
||||
catalogBroadcaster(catalogEntityRegistry.items);
|
||||
});
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
import React from "react";
|
||||
import { observable, makeObservable } from "mobx";
|
||||
import { observable, makeObservable, reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { Redirect, Route, Router, Switch } from "react-router";
|
||||
import { history } from "../navigation";
|
||||
@ -37,7 +37,7 @@ import { webFrame } from "electron";
|
||||
import { ClusterPageRegistry, getExtensionPageUrl } from "../../extensions/registries/page-registry";
|
||||
import { ExtensionLoader } from "../../extensions/extension-loader";
|
||||
import { appEventBus } from "../../common/event-bus";
|
||||
import { catalogBroadcastHandler, requestMain } from "../../common/ipc";
|
||||
import { requestMain } from "../../common/ipc";
|
||||
import whatInput from "what-input";
|
||||
import { clusterSetFrameIdHandler } from "../../common/cluster-ipc";
|
||||
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}`);
|
||||
await Terminal.preloadFonts();
|
||||
await requestMain(clusterSetFrameIdHandler, App.clusterId);
|
||||
await requestMain(catalogBroadcastHandler);
|
||||
|
||||
const cluster = ClusterStore.getInstance().getById(App.clusterId);
|
||||
|
||||
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();
|
||||
setTimeout(() => {
|
||||
appEventBus.emit({
|
||||
|
||||
@ -40,7 +40,6 @@ import { SidebarItem } from "./sidebar-item";
|
||||
import { Apps } from "../+apps";
|
||||
import * as routes from "../../../common/routes";
|
||||
import { Config } from "../+config";
|
||||
import { App } from "../app";
|
||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||
|
||||
interface Props {
|
||||
@ -179,7 +178,7 @@ export class Sidebar extends React.Component<Props> {
|
||||
}
|
||||
|
||||
get clusterEntity() {
|
||||
return catalogEntityRegistry.getById(App.clusterId);
|
||||
return catalogEntityRegistry.activeEntity;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user