gpt4 book ai didi

electron - 有没有办法让Golden Layout弹出窗口与Electron窗口一起使用?

转载 作者:行者123 更新时间:2023-12-03 12:28:12 33 4
gpt4 key购买 nike

我正在尝试要在Electron中运行的JHipster应用程序。我有用于窗口/ Pane 管理和跨 Pane 通信的Golden Layout。我在使用技术方面遇到了一些问题,包括:

  • 我不能同时将多个 Pane 弹出到自己的 Electron 窗口中。相反,我在控制台中收到Uncaught Error: Can't create config, layout not yet initialised错误。
  • 弹出 Electron 窗口时,三分之二的 Pane 不显示任何内容,我不确定原因是什么。有任何想法或建议吗?内容示例之一是传单 map ,另一个内容是“PowerPoint预览”,它实际上只是模拟幻灯片外观的div。
  • 我还没有做到这一点,但是我想当我打开多个窗口时,在弹出的 Electron 窗口之间无法通信。现在,各 Pane 之间使用Golden Layout的glEventHub发射进行相互通信。当我过桥时,我有一条途径可以探索,即Electron ipcRenderer。

  • 一些借用的代码在这里(由于我是公司的 secret 信息,所以我无法分享其中的大部分内容):

    electronic.js:
    const electron = require('electron');
    const app = electron.app;
    const BrowserWindow = electron.BrowserWindow;

    const path = require('path');
    const isDev = require('electron-is-dev');

    let mainWindow;

    function createWindow() {
    mainWindow = new BrowserWindow({width: 900, height: 680});
    mainWindow.loadURL(isDev ? 'http://localhost:9000' : `file://${path.join(__dirname, '../build/index.html')}`);
    if (isDev) {
    // Open the DevTools.
    //BrowserWindow.addDevToolsExtension('<location to your react chrome extension>');
    mainWindow.webContents.openDevTools();
    }
    mainWindow.on('closed', () => mainWindow = null);
    }

    app.on('ready', createWindow);

    app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
    app.quit();
    }
    });

    app.on('activate', () => {
    if (mainWindow === null) {
    createWindow();
    }
    });


    goldenLayoutComponent.tsx,黄金版面的补丁:
    import React from "react";
    import ReactDOM from "react-dom";
    // import "./goldenLayout-dependencies";
    import GoldenLayout from "golden-layout";
    import "golden-layout/src/css/goldenlayout-base.css";
    import "golden-layout/src/css/goldenlayout-dark-theme.css";
    import $ from "jquery";

    interface IGoldenLayoutProps {
    htmlAttrs: {},
    config: any,
    registerComponents: Function
    }

    interface IGoldenLayoutState {
    renderPanels: Set<any>
    }

    interface IContainerRef {
    current: any
    }

    export class GoldenLayoutComponent extends React.Component <IGoldenLayoutProps, IGoldenLayoutState> {
    goldenLayoutInstance = undefined;
    state = {
    renderPanels: new Set<any>()
    };
    containerRef: IContainerRef = React.createRef();

    render() {
    const panels = Array.from(this.state.renderPanels || []);
    return (
    <div ref={this.containerRef as any} {...this.props.htmlAttrs}>
    {panels.map((panel, index) => {
    return ReactDOM.createPortal(
    panel._getReactComponent(),
    panel._container.getElement()[0]
    );
    })}
    </div>
    );
    }

    componentRender(reactComponentHandler) {
    this.setState(state => {
    const newRenderPanels = new Set(state.renderPanels);
    newRenderPanels.add(reactComponentHandler);
    return { renderPanels: newRenderPanels };
    });
    }
    componentDestroy(reactComponentHandler) {
    this.setState(state => {
    const newRenderPanels = new Set(state.renderPanels);
    newRenderPanels.delete(reactComponentHandler);
    return { renderPanels: newRenderPanels };
    });
    }

    componentDidMount() {
    this.goldenLayoutInstance = new GoldenLayout(
    this.props.config || {},
    this.containerRef.current
    );
    if (this.props.registerComponents instanceof Function)
    this.props.registerComponents(this.goldenLayoutInstance);
    this.goldenLayoutInstance.reactContainer = this;
    this.goldenLayoutInstance.init();
    }
    }


    // Patching internal GoldenLayout.__lm.utils.ReactComponentHandler:

    const ReactComponentHandler = GoldenLayout["__lm"].utils.ReactComponentHandler;

    class ReactComponentHandlerPatched extends ReactComponentHandler {
    _container: any;
    _reactClass: any;
    _render() {
    const reactContainer = this._container.layoutManager.reactContainer; // Instance of GoldenLayoutComponent class
    if (reactContainer && reactContainer.componentRender)
    reactContainer.componentRender(this);
    }
    _destroy() {
    // ReactDOM.unmountComponentAtNode( this._container.getElement()[ 0 ] );
    this._container.off("open", this._render, this);
    this._container.off("destroy", this._destroy, this);
    }

    _getReactComponent() {
    // the following method is absolute copy of the original, provided to prevent depenency on window.React
    const defaultProps = {
    glEventHub: this._container.layoutManager.eventHub,
    glContainer: this._container
    };
    const props = $.extend(defaultProps, this._container._config.props);
    return React.createElement(this._reactClass, props);
    }
    }

    GoldenLayout["__lm"].utils.ReactComponentHandler = ReactComponentHandlerPatched;

    任何帮助或对这些问题的见解将不胜感激。提前致谢!

    最佳答案

    如果您仍在寻找解决方案,我已经解决了1和2,如果您想查看我的解决方案,可以在this存储库中看到。
    但这基本上是这样的:
    1:弹出窗口的路径与主窗口的路径不同,因此我只需要在我的需求中添加一个try catch,就必须设置nativeWindowOpen = true创建浏览器窗口时。
    2:我认为1后解决自我

    关于electron - 有没有办法让Golden Layout弹出窗口与Electron窗口一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59737414/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com