Electron 多窗口电子应用程序结构

Electron 多窗口电子应用程序结构,electron,dashboard,responsiveness,multi-window,Electron,Dashboard,Responsiveness,Multi Window,我正在开发一个仪表板应用程序,我的目的是通过选择预定义的窗口布局来定制多个窗口。图示布局如下所示: 我目前正在拍摄电子框架。我的方法是通过捕获屏幕大小并计算窗口大小和位置来创建多个BrowserWindow。我就是这样写的: // app/main.js // Module to control application life. var app = require('electron').app; // Module to create native browser window. va

我正在开发一个仪表板应用程序,我的目的是通过选择预定义的窗口布局来定制多个窗口。图示布局如下所示:

我目前正在拍摄电子框架。我的方法是通过捕获屏幕大小并计算窗口大小和位置来创建多个BrowserWindow。我就是这样写的:

// app/main.js

// Module to control application life.
var app = require('electron').app;

// Module to create native browser window.
var BrowserWindow = require('electron').BrowserWindow;
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function () {
        app.quit();
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function () {
    var screenElectron = require('electron').screen;
    var mainScreen = screenElectron.getPrimaryDisplay();
    var extScreen = null;
    var allScreens = screenElectron.getAllDisplays();
    var screenWidth = mainScreen.workArea.width;
    var screenHeight = mainScreen.workArea.height;
    var screenX = mainScreen.workArea.x;
    var screenY = mainScreen.workArea.y;
    console.log("Number of screens: " + allScreens.length);      
    console.log("Main screen: " + JSON.stringify(screenElectron.getPrimaryDisplay()));
    console.log("All screen: " + JSON.stringify(screenElectron.getAllDisplays()));

    console.log("Current display: " + Math.floor(screenWidth / 4) + " ; " + Math.floor(screenHeight / 4) + " ; " + screenX + " ; " + (screenY + Math.floor(screenHeight * 1 / 4)));
    // Create the browser window.
    mainWindow = new BrowserWindow({
        width: Math.floor(screenWidth * 50 / 100),
        height: Math.floor(screenHeight * 50 / 100)
    });
    var win1 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight / 4),
        x: screenX,
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })

    var win2 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight / 4),
        x: screenX,
        y: screenY + Math.floor(screenHeight * 1 / 4),
        resizable: false,
        backgroundColor: '#2e2c29'
    })

    var win3 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight / 4),
        x: screenX,
        y: screenY + Math.floor(screenHeight * 2 / 4),
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win4 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight / 4),
        x: screenX,
        y: screenY + Math.floor(screenHeight * 3 / 4),
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win5 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight * 3 / 4),
        x: screenX + Math.floor(screenWidth * 3 / 4),
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win6 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 4),
        height: Math.floor(screenHeight * 1 / 4),
        x: screenX + Math.floor(screenWidth * 3 / 4),
        y: screenY + Math.floor(screenHeight * 3 / 4),
        resizable: false,
        backgroundColor: '#2e2c29'
    })

    var win7 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 8),
        height: Math.floor(screenHeight * 1 / 6),
        x: screenX + Math.floor(screenWidth * 2 / 8),
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win8 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 8),
        height: Math.floor(screenHeight * 1 / 6),
        x: screenX + Math.floor(screenWidth * 3 / 8),
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win9 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 8),
        height: Math.floor(screenHeight * 1 / 6),
        x: screenX + Math.floor(screenWidth * 4 / 8),
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })
    var win10 = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth / 8),
        height: Math.floor(screenHeight * 1 / 6),
        x: screenX + Math.floor(screenWidth * 5 / 8),
        y: screenY,
        resizable: false,
        backgroundColor: '#2e2c29'
    })

    var focusWin = new BrowserWindow({
        parent: mainWindow,
        frame: false,
        width: Math.floor(screenWidth * 50 / 100),
        height: Math.floor(screenHeight * 5 / 6),
        x: screenX + Math.floor(screenWidth / 4),
        y: screenY + Math.floor(screenHeight * 1 / 6),
        resizable: false,
        backgroundColor: '#2e2c29'
    })


    // Load the index.html of the app.
    mainWindow.loadURL('file://' + __dirname + '/index.html');

    win1.loadURL('file://' + __dirname + '/index.html');
    win2.loadURL('file://' + __dirname + '/index.html');
    win3.loadURL('file://' + __dirname + '/index.html');
    win4.loadURL('file://' + __dirname + '/index.html');
    win5.loadURL('file://' + __dirname + '/index.html');
    win6.loadURL('file://' + __dirname + '/index.html');
    win7.loadURL('file://' + __dirname + '/index.html');
    win8.loadURL('file://' + __dirname + '/index.html');
    win9.loadURL('file://' + __dirname + '/index.html');
    win10.loadURL('file://' + __dirname + '/index.html');
    focusWin.loadURL('file://' + __dirname + '/index.html');

});

有人能告诉我这是否是一个好的结构/策略吗,因为我正在使所有窗口相互独立,而不是将所有内容都包含在一个窗口中的普通web应用程序?我最担心的是这些窗口的响应能力以及每个窗口的内容。感谢您的建议……

已经一年了,您是否达成了一些可以共享的增强结构?