const { app, BrowserWindow, BrowserView, Tray, Menu, nativeImage } = require('electron') const por = require('child_process'); const { error } = require('console'); const { stdout, stderr } = require('process'); let tray function createWindow () { const mainWindow = new BrowserWindow({ width: 1000, height: 600,// 设置打开的窗口大小 useContentSize: true, enableLargerThanScreen: true, autoHideMenuBar: true, icon: 'logo.png', webPreferences: { // contextIsolation: false, // worldSafeExecuteJavaScript:a flse, // webSecurity: false, nodeIntegration: true, // 是否集成node.js,解决require is not defined问题 // nodeIntegrationInWorker: true, // webviewTag: true, // 解决webview无法显示问题 // enableRemoteModule: true, } }); var view = new BrowserView() // new出对象 mainWindow.setBrowserView(view) // 在主窗口中设置view可用 view.setBounds({x:0,y:0, width: 1000,height: 600}) // 定义view的具体样式和位置 view.setAutoResize({width: true, height: true}) view.useContentSize = true view.webContents.loadURL('http://localhost:3004/html') // wiew载入的页面 // mainWindow.setIcon('https://agent-crm.luojigou.vip/crm-api//20210323/logo_icon.png') // mainWindow.loadFile('./app/build/index.html') } app.whenReady().then(() => { const icon = nativeImage.createFromPath('./logo.png') tray = new Tray(icon) const contextMenu = Menu.buildFromTemplate([]) tray.setContextMenu(contextMenu) tray.setToolTip('This is my application') tray.setTitle('This is my title') createWindow() // por.exec('node nodemod.js') }) app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } })