const { app, BrowserWindow, Menu } = require('electron') const path = require('path') //热加载 const reloader = require('electron-reloader') reloader(module) /** * 在 Electron 中,只有在 app 模块的 ready 事件被激发后才能创建浏览器窗口。 * 您可以通过使用 app.whenReady() API来监听此事件。 在whenReady()成功后调用createWindow()。 */ app.whenReady().then(() => { createWindow() convertVodie() }) /** * 关闭所有窗口时退出应用 */ app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) const createWindow = () => { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js'), //允许运行子线程 nodeIntegrationInWorker: true, //开启node支持 nodeIntegration: true, enableRemoteModule: true, //关闭安全性验证 contextIsolation: false, //允许跨域 webSecurity: false } }) app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) win.webContents.openDevTools(); win.loadFile('view/index/index.html') // win.loadURL('http://www.baidu.com') }