BrowserWindow - BrowserWindow([options])

概述

创建一个新的BrowserWindow实例

基本信息

属性
模块 BrowserWindow
类型 Method
鸿蒙支持 支持

OHOS 依赖与基本表现

属性
系统权限依赖 无需申请
添加JIT权限 支持
坚盾模式 支持

差异说明

属性
是否存在差异 存在差异
差异说明 1.创建多窗口时需要创建托盘 2.可通过displayId指定创建在哪个屏幕上

Demo

const { app, BrowserWindow, Tray, nativeImage, screen } = require('electron');
const path = require('path');

let tray;
let windows = [];

function createWindows() {
  tray = new Tray(nativeImage.createFromPath(path.join(__dirname, 'electron_white.png')));
  const displays = screen.getAllDisplays();
  console.log('Electron Screen Test. 当前屏幕信息:');
  displays.forEach((display, index) => {
    console.log(`Electron Screen Test. ${index}:`, {
      displayId: display.id,
      bounds: display.bounds,
      size: display.size,
      scaleFactor: display.scaleFactor
    });
    let win;
    if(display.id == 0) {
      win = new BrowserWindow({
        displayId: display.id,
        width: 800,
        height: 600,
        webPreferences: {
          nodeIntegration: true,
          contextIsolation: false
        }
      });
    } else {
      win = new BrowserWindow({
        windowInfo: {
          type: 'floatWindow'
        },
        parent: windows[0],
        displayId: display.id,
        width: 400,
        height: 300,
        frame: false,
        webPreferences: {
          nodeIntegration: true,
          contextIsolation: false
        }
      });
    }

    win.loadFile('index.html');
    windows.push(win);
  });
}

app.whenReady().then(() => {
  createWindows();
});