2

我正在开发仪表板应用程序,我的目的是通过选择预定义的窗口布局来定制多个窗口。图示布局将是这样的: 仪表板计划布局

我目前正在为 Electron 框架拍摄。我这样做的方式是通过捕获屏幕大小并计算窗口大小和位置来创建多个 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 应用程序?我最担心的是这些窗口的响应能力和每个窗口的内容。在这里欣赏任何建议...

4

0 回答 0