1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

cluster-view battling -- part 2

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-08-07 09:59:07 +03:00
parent 4543d8e178
commit aa718dd7e1
5 changed files with 50 additions and 25 deletions

View File

@ -3,6 +3,14 @@ import { ClusterId, clusterStore } from "./cluster-store";
import { tracker } from "./tracker"; import { tracker } from "./tracker";
export const clusterIpc = { export const clusterIpc = {
// todo: remove
init: createIpcChannel({
channel: "cluster:init",
handle: async (clusterId: ClusterId) => {
return clusterStore.getById(clusterId)?.pushState();
},
}),
activate: createIpcChannel({ activate: createIpcChannel({
channel: "cluster:activate", channel: "cluster:activate",
handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => { handle: async (clusterId: ClusterId = clusterStore.activeClusterId) => {

View File

@ -129,7 +129,7 @@ export function broadcastIpc({ channel, webContentId, filter, args = [] }: IpcBr
} }
views.forEach(webContent => { views.forEach(webContent => {
const type = webContent.getType(); const type = webContent.getType();
logger.debug(`[IPC]: sending message "${channel}" to ${type}=${webContent.id}`, { args }); logger.debug(`[IPC]: broadcasting "${channel}" to ${type}=${webContent.id}`, { args });
webContent.send(channel, ...[args].flat()); webContent.send(channel, ...[args].flat());
}) })
} }

View File

@ -31,10 +31,13 @@ import { isAllowedResource } from "../../common/rbac";
import { ClusterSettings, clusterSettingsRoute } from "./+cluster-settings"; import { ClusterSettings, clusterSettingsRoute } from "./+cluster-settings";
import { ErrorBoundary } from "./error-boundary"; import { ErrorBoundary } from "./error-boundary";
import { Terminal } from "./dock/terminal"; import { Terminal } from "./dock/terminal";
import { getHostedClusterId } from "../../common/cluster-store";
import { clusterIpc } from "../../common/cluster-ipc";
@observer @observer
export class App extends React.Component { export class App extends React.Component {
static async init() { static async init() {
await clusterIpc.init.invokeFromRenderer(getHostedClusterId())
await Terminal.preloadFonts() await Terminal.preloadFonts()
} }

View File

@ -1,8 +1,8 @@
.ClusterView { .ClusterView {
width: 100%; width: 100%;
height: 100%; height: 100%;
border: 0; flex: 1;
//display: none; display: none;
&.loaded { &.loaded {
display: flex; display: flex;

View File

@ -5,53 +5,67 @@ import { autorun, computed, observable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { getMatchedClusterId } from "./cluster-view.route"; import { getMatchedClusterId } from "./cluster-view.route";
import { Cluster } from "../../../main/cluster";
import { ClusterStatus } from "./cluster-status"; import { ClusterStatus } from "./cluster-status";
import logger from "../../../main/logger";
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component {
static views = observable.map<ClusterId, WebviewTag>() static views = observable.map<ClusterId, WebviewTag>()
static isLoaded = observable.map<ClusterId, boolean>() static isLoaded = observable.map<ClusterId, boolean>()
@observable.ref placeholder: HTMLElement;
@computed get cluster() { @computed get cluster() {
return clusterStore.getById(getMatchedClusterId()) return clusterStore.getById(getMatchedClusterId())
} }
@computed get clusterView() {
return ClusterView.views.get(this.cluster?.id)
}
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
autorun(() => this.activateView(this.cluster)) autorun(() => {
if (this.cluster) {
this.initView(this.cluster.id)
this.activateView(this.cluster.id)
}
})
]) ])
} }
// fixme initView = (clusterId: ClusterId) => {
activateView = (cluster: Cluster) => { if (ClusterView.views.has(clusterId)) {
if (!cluster || ClusterView.views.has(cluster.id)) {
return; return;
} }
const view = document.createElement("webview"); const webview = document.createElement("webview");
view.className = "ClusterView" webview.className = "ClusterView"
view.setAttribute("nodeintegration", "true") webview.setAttribute("src", `//${clusterId}.${location.host}`)
view.setAttribute("enableremotemodule", "true") webview.setAttribute("nodeintegration", "true")
view.addEventListener("did-finish-load", () => { webview.setAttribute("enableremotemodule", "true")
console.log('CLUSTER VIEW READY!', cluster) webview.addEventListener("did-finish-load", () => {
// view.openDevTools() webview.openDevTools();
webview.classList.add("loaded");
ClusterView.isLoaded.set(clusterId, true)
}); });
view.addEventListener("did-fail-load", event => { webview.addEventListener("did-fail-load", (event) => {
// todo: handle logger.error("failed to load lens-webview", event)
}); });
view.src = `${location.protocol}//${cluster.id}.${location.host}` document.body.appendChild(webview);
document.body.appendChild(view); ClusterView.views.set(clusterId, webview);
ClusterView.views.set(cluster.id, view); }
activateView = async (clusterId: ClusterId) => {
const view = ClusterView.views.get(clusterId);
const isLoaded = ClusterView.isLoaded.has(clusterId);
if (view && isLoaded && this.placeholder) {
this.placeholder.replaceWith(view);
}
} }
render() { render() {
const { cluster } = this; const { cluster } = this;
if (cluster) { if (cluster) {
return <ClusterStatus clusterId={cluster.id}/> if (!cluster.accessible) {
return <ClusterStatus clusterId={cluster.id}/>
}
return <div ref={e => this.placeholder = e}/>
} }
} }
} }