From 0ba275b332911ae3cb75a8dc13c0d58f9fdea3cc Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 7 Aug 2020 10:54:21 +0300 Subject: [PATCH] cluster-view battling -- part 3 Signed-off-by: Roman --- src/common/cluster-ipc.ts | 8 -------- src/common/cluster-store.ts | 2 +- src/common/ipc.ts | 2 +- src/main/cluster-manager.ts | 9 +-------- src/renderer/components/app.tsx | 5 ++--- .../components/cluster-manager/cluster-status.tsx | 2 +- src/renderer/components/cluster-manager/cluster-view.tsx | 6 +++++- 7 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/common/cluster-ipc.ts b/src/common/cluster-ipc.ts index 6782578c40..5d5dfe206d 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/cluster-ipc.ts @@ -3,14 +3,6 @@ import { ClusterId, clusterStore } from "./cluster-store"; import { tracker } from "./tracker"; export const clusterIpc = { - // todo: remove - init: createIpcChannel({ - channel: "cluster:init", - handle: async (clusterId: ClusterId) => { - return clusterStore.getById(clusterId)?.pushState(); - }, - }), - activate: createIpcChannel({ channel: "cluster:activate", handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => { diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index e4987d85a1..90e27a4385 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -64,7 +64,7 @@ export class ClusterStore extends BaseStore { if (ipcRenderer) { ipcRenderer.on("cluster:state", (event, clusterState: ClusterState) => { this.applyWithoutSync(() => { - logger.debug(`[CLUSTER-STORE]: received state update for cluster=${clusterState.id}`, clusterState); + logger.info(`[CLUSTER-STORE]: received state update for cluster=${clusterState.id}`, clusterState); const cluster = this.getById(clusterState.id); if (cluster) cluster.updateModel(clusterState) }) diff --git a/src/common/ipc.ts b/src/common/ipc.ts index 2c18793801..fa79942ddc 100644 --- a/src/common/ipc.ts +++ b/src/common/ipc.ts @@ -33,7 +33,7 @@ export interface IpcChannelInit { once?: boolean; // todo: add support } -export function createIpcChannel({ autoBind = false, mode = IpcMode.ASYNC, timeout = 0, handle, channel }: IpcChannelInit) { +export function createIpcChannel({ autoBind = true, mode = IpcMode.ASYNC, timeout = 0, handle, channel }: IpcChannelInit) { channel = `${mode}:${channel}` const ipcChannel = { diff --git a/src/main/cluster-manager.ts b/src/main/cluster-manager.ts index 97b9a80871..9eaebc9034 100644 --- a/src/main/cluster-manager.ts +++ b/src/main/cluster-manager.ts @@ -1,8 +1,8 @@ +import "../common/cluster-ipc"; import type http from "http" import { autorun } from "mobx"; import { ClusterId, clusterStore } from "../common/cluster-store" import { Cluster } from "./cluster" -import { clusterIpc } from "../common/cluster-ipc"; import logger from "./logger"; export class ClusterManager { @@ -29,13 +29,6 @@ export class ClusterManager { }, { delay: 250 }); - - // listen for ipc-events that must/can be handled *only* in main-process (nodeIntegration=true) - clusterIpc.activate.handleInMain(); - clusterIpc.disconnect.handleInMain(); - clusterIpc.installFeature.handleInMain(); - clusterIpc.uninstallFeature.handleInMain(); - clusterIpc.upgradeFeature.handleInMain(); } stop() { diff --git a/src/renderer/components/app.tsx b/src/renderer/components/app.tsx index 1f747ede31..b96277b245 100755 --- a/src/renderer/components/app.tsx +++ b/src/renderer/components/app.tsx @@ -31,14 +31,13 @@ import { isAllowedResource } from "../../common/rbac"; import { ClusterSettings, clusterSettingsRoute } from "./+cluster-settings"; import { ErrorBoundary } from "./error-boundary"; import { Terminal } from "./dock/terminal"; -import { getHostedClusterId } from "../../common/cluster-store"; -import { clusterIpc } from "../../common/cluster-ipc"; +import { getHostedCluster } from "../../common/cluster-store"; @observer export class App extends React.Component { static async init() { - await clusterIpc.init.invokeFromRenderer(getHostedClusterId()) await Terminal.preloadFonts() + await getHostedCluster().whenInitialized; } get startURL() { diff --git a/src/renderer/components/cluster-manager/cluster-status.tsx b/src/renderer/components/cluster-manager/cluster-status.tsx index e2fb6c17e8..93fb2ada91 100644 --- a/src/renderer/components/cluster-manager/cluster-status.tsx +++ b/src/renderer/components/cluster-manager/cluster-status.tsx @@ -44,7 +44,7 @@ export class ClusterStatus extends React.Component { error: res.error, }); }) - await this.refreshClusterState(); + // await this.refreshClusterState(); } componentWillUnmount() { diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index 40561efbb0..ba6469cdee 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -39,8 +39,10 @@ export class ClusterView extends React.Component { webview.setAttribute("src", `//${clusterId}.${location.host}`) webview.setAttribute("nodeintegration", "true") webview.setAttribute("enableremotemodule", "true") + // webview.addEventListener("did-start-loading", () => { + // webview.openDevTools(); + // }); webview.addEventListener("did-finish-load", () => { - webview.openDevTools(); webview.classList.add("loaded"); ClusterView.isLoaded.set(clusterId, true) }); @@ -52,9 +54,11 @@ export class ClusterView extends React.Component { } activateView = async (clusterId: ClusterId) => { + const cluster = clusterStore.getById(clusterId); const view = ClusterView.views.get(clusterId); const isLoaded = ClusterView.isLoaded.has(clusterId); if (view && isLoaded && this.placeholder) { + cluster.pushState(); // fixme this.placeholder.replaceWith(view); } }