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

cluster-view bugfixing, attempt 100500..

Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Roman 2020-08-07 16:18:56 +03:00 committed by Lauri Nevala
parent 1204e9e8aa
commit 3e86729fea
6 changed files with 58 additions and 44 deletions

View File

@ -49,7 +49,7 @@ export function createIpcChannel({ autoBind = true, mode = IpcMode.ASYNC, timeou
if (resolved) return; if (resolved) return;
res.msgId = req.msgId; // return back to sender to be able to handle response res.msgId = req.msgId; // return back to sender to be able to handle response
resolved = true resolved = true
logger.info(`[IPC]: sending response to "${channel}"`, res); logger.debug(`[IPC]: sending response to "${channel}"`, res);
if (mode === IpcMode.ASYNC) { if (mode === IpcMode.ASYNC) {
event.reply(channel, res); event.reply(channel, res);
} }
@ -82,7 +82,6 @@ export function createIpcChannel({ autoBind = true, mode = IpcMode.ASYNC, timeou
msgId: getRandId({ prefix: "ipc-msg-id" }), msgId: getRandId({ prefix: "ipc-msg-id" }),
args: args, args: args,
} }
logger.info(`[IPC]: "${channel}" sending message to main`, req);
if (mode === IpcMode.ASYNC) { if (mode === IpcMode.ASYNC) {
ipcRenderer.send(channel, req) ipcRenderer.send(channel, req)
} }
@ -94,7 +93,7 @@ export function createIpcChannel({ autoBind = true, mode = IpcMode.ASYNC, timeou
if (req.msgId === res.msgId) { if (req.msgId === res.msgId) {
const meta = { ...req, ...res }; const meta = { ...req, ...res };
if (res.data) { if (res.data) {
logger.info(`[IPC]: "${channel}" resolve`, meta); logger.debug(`[IPC]: "${channel}" resolve`, meta);
resolve(res.data); resolve(res.data);
} }
if (res.error) { if (res.error) {

View File

@ -1,13 +1,13 @@
.ClusterManager { .ClusterManager {
display: grid; display: grid;
grid-template-areas: "menu lens-view" "menu lens-view" "bottom-bar bottom-bar"; grid-template-areas: "menu main" "menu main" "bottom-bar bottom-bar";
grid-template-rows: auto 1fr min-content; grid-template-rows: auto 1fr min-content;
grid-template-columns: min-content 1fr; grid-template-columns: min-content 1fr;
height: 100%; height: 100%;
#lens-view { main {
position: relative; position: relative;
grid-area: lens-view; grid-area: main;
display: flex; display: flex;
} }

View File

@ -30,7 +30,7 @@ export class ClusterManager extends React.Component {
return ( return (
<div className="ClusterManager"> <div className="ClusterManager">
<div id="draggable-top"/> <div id="draggable-top"/>
<div id="lens-view"> <main>
<Switch> <Switch>
<Route component={LandingPage} {...landingRoute}/> <Route component={LandingPage} {...landingRoute}/>
<Route component={Preferences} {...preferencesRoute}/> <Route component={Preferences} {...preferencesRoute}/>
@ -39,7 +39,7 @@ export class ClusterManager extends React.Component {
<Route component={ClusterView} {...clusterViewRoute}/> <Route component={ClusterView} {...clusterViewRoute}/>
<Redirect exact from="/" to={this.startUrl}/> <Redirect exact from="/" to={this.startUrl}/>
</Switch> </Switch>
</div> </main>
<ClustersMenu/> <ClustersMenu/>
<BottomBar/> <BottomBar/>
</div> </div>

View File

@ -8,11 +8,12 @@ import { computed, observable } from "mobx";
import { clusterIpc } from "../../../common/cluster-ipc"; import { clusterIpc } from "../../../common/cluster-ipc";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { Button } from "../button"; import { Button } from "../button";
import { cssNames } from "../../utils"; import { cssNames, IClassName } from "../../utils";
import { Cluster } from "../../../main/cluster"; import { Cluster } from "../../../main/cluster";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
interface Props { interface Props {
className?: IClassName;
clusterId: ClusterId; clusterId: ClusterId;
} }
@ -68,7 +69,7 @@ export class ClusterStatus extends React.Component<Props> {
const failureReason = cluster.failureReason; const failureReason = cluster.failureReason;
const isError = hasErrors || isDisconnected; const isError = hasErrors || isDisconnected;
return ( return (
<div className="ClusterStatus flex column gaps"> <div className={cssNames("ClusterStatus flex column gaps", this.props.className)}>
{isError && ( {isError && (
<Icon <Icon
material="cloud_off" material="cloud_off"

View File

@ -1,10 +1,18 @@
.ClusterView { .ClusterView {
width: 100%; width: 100%;
height: 100%; height: 100%;
flex: 1;
display: none; display: none;
&.loaded { &.loaded {
display: flex; display: flex;
} }
} }
//#lens-views {
// position: absolute;
// left: 0;
// top: 0;
// width: 0;
// height: 0;
// overflow: hidden;
//}

View File

@ -1,7 +1,7 @@
import "./cluster-view.scss" import "./cluster-view.scss"
import React from "react"; import React from "react";
import { WebviewTag } from "electron" import { WebviewTag } from "electron"
import { autorun, computed, observable } from "mobx"; import { action, 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";
@ -9,65 +9,71 @@ import { ClusterStatus } from "./cluster-status";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
import { clusterIpc } from "../../../common/cluster-ipc"; import { clusterIpc } from "../../../common/cluster-ipc";
const lensViews = observable.map<ClusterId, WebviewTag>()
const isLoaded = observable.map<ClusterId, boolean>()
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component {
static views = observable.map<ClusterId, WebviewTag>() protected placeholder: HTMLElement;
static isLoaded = observable.map<ClusterId, boolean>()
@observable.ref placeholder: HTMLElement;
@computed get cluster() { @computed get cluster() {
return clusterStore.getById(getMatchedClusterId()) return clusterStore.getById(getMatchedClusterId())
} }
// fixme: attach/detach doesn't work properly
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, [ // disposeOnUnmount(this, [
autorun(() => { // autorun(() => {
if (this.cluster) { // const activeClusterId = this.cluster?.id;
this.initView(this.cluster.id) // if (activeClusterId) {
this.attachView(this.cluster.id) // this.initView(activeClusterId);
} // Array.from(lensViews).forEach(([clusterId, view]) => {
}) // if (activeClusterId === clusterId && isLoaded.has(clusterId)) {
]) // this.placeholder.appendChild(view)
// } else {
// view.parentElement.removeChild(view);
// }
// })
// }
// }),
// ])
} }
initView = (clusterId: ClusterId) => { @action
if (ClusterView.views.has(clusterId)) { initView(clusterId: ClusterId) {
if (lensViews.has(clusterId)) {
return; return;
} }
logger.info(`[WEBVIEW]: init view for clusterId=${clusterId}`)
const webview = document.createElement("webview"); const webview = document.createElement("webview");
webview.className = "ClusterView" webview.className = "ClusterView"
webview.setAttribute("src", `//${clusterId}.${location.host}`) webview.setAttribute("src", `//${clusterId}.${location.host}`)
webview.setAttribute("nodeintegration", "true") webview.setAttribute("nodeintegration", "true")
webview.setAttribute("enableremotemodule", "true") webview.setAttribute("enableremotemodule", "true")
webview.addEventListener("did-finish-load", () => { webview.addEventListener("did-finish-load", () => {
// webview.openDevTools() logger.info(`[WEBVIEW]: loaded, clusterId=${clusterId}`)
webview.classList.add("loaded"); isLoaded.set(clusterId, true);
clusterIpc.init.invokeFromRenderer(clusterId); // push-state to webview webview.classList.add("loaded")
ClusterView.isLoaded.set(clusterId, true); clusterIpc.init.invokeFromRenderer(clusterId); // push cluster-state to webview
}); });
webview.addEventListener("did-fail-load", (event) => { webview.addEventListener("did-fail-load", (event) => {
logger.error("failed to load lens-webview", event) logger.error(`[WEBVIEW]: failed to load, clusterId=${clusterId}`, event)
}); });
lensViews.set(clusterId, webview);
document.body.appendChild(webview); document.body.appendChild(webview);
ClusterView.views.set(clusterId, webview);
} }
attachView = async (clusterId: ClusterId) => { bindRef = (elem: HTMLElement) => {
const view = ClusterView.views.get(clusterId); this.placeholder = elem;
const isLoaded = ClusterView.views.has(clusterId);
if (view && isLoaded && this.placeholder) {
this.placeholder.replaceWith(view);
}
} }
render() { render() {
const { cluster } = this; const { cluster } = this;
if (cluster) { const showStatus = cluster && !cluster.accessible;
if (!cluster.accessible) { return (
return <ClusterStatus clusterId={cluster.id}/> <div className="ClusterView" ref={this.bindRef}>
} {showStatus && <ClusterStatus clusterId={cluster.id}/>}
return <div ref={e => this.placeholder = e}/> </div>
} )
} }
} }