主进程创建并关闭多个渲染进程
主脚本指定了运行主进程的 Electron 应用程序的入口 , 通常是man.js文件 , Electron 应用程序只能有一个主进程。 1. 为了管理应用程序的生命周期事件以及创建和控制浏览器窗口,需要从 electron 包导入了 app 和 BrowserWindow 模块 , const { app, BrowserWindow } = require('electron') 2. 定义一个创建 新的浏览窗口 的函数并将 nodeIntegration 设置为 true,将 index.html 文件加载到窗口中, function createWindow () { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { //注意: 设置 nodeIntegration 选项为 true 表示渲染过程中可以访问Node.js API nodeIntegration: true } }) win.loadFile('index.html') } 3. 调用 createWindow 方法,在 electron app 第一次 被初始化 时创建一个新的窗口 app.whenReady().then(createWindow) 4. 添加一个新的侦听器