main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const { app, BrowserWindow, BrowserView, Tray, Menu, nativeImage } = require('electron')
  2. const por = require('child_process');
  3. const { error } = require('console');
  4. const { stdout, stderr } = require('process');
  5. let tray
  6. function createWindow () {
  7. const mainWindow = new BrowserWindow({
  8. width: 1000,
  9. height: 600,// 设置打开的窗口大小
  10. useContentSize: true,
  11. enableLargerThanScreen: true,
  12. autoHideMenuBar: true,
  13. icon: 'logo.png',
  14. webPreferences: {
  15. // contextIsolation: false,
  16. // worldSafeExecuteJavaScript:a flse,
  17. // webSecurity: false,
  18. nodeIntegration: true, // 是否集成node.js,解决require is not defined问题
  19. // nodeIntegrationInWorker: true,
  20. // webviewTag: true, // 解决webview无法显示问题
  21. // enableRemoteModule: true,
  22. }
  23. });
  24. var view = new BrowserView() // new出对象
  25. mainWindow.setBrowserView(view) // 在主窗口中设置view可用
  26. view.setBounds({x:0,y:0, width: 1000,height: 600}) // 定义view的具体样式和位置
  27. view.setAutoResize({width: true, height: true})
  28. view.useContentSize = true
  29. view.webContents.loadURL('http://localhost:3004/html') // wiew载入的页面
  30. // mainWindow.setIcon('https://agent-crm.luojigou.vip/crm-api//20210323/logo_icon.png')
  31. // mainWindow.loadFile('./app/build/index.html')
  32. }
  33. app.whenReady().then(() => {
  34. const icon = nativeImage.createFromPath('./logo.png')
  35. tray = new Tray(icon)
  36. const contextMenu = Menu.buildFromTemplate([])
  37. tray.setContextMenu(contextMenu)
  38. tray.setToolTip('This is my application')
  39. tray.setTitle('This is my title')
  40. createWindow()
  41. // por.exec('node nodemod.js')
  42. })
  43. app.on('window-all-closed', () => {
  44. if (process.platform !== 'darwin') {
  45. app.quit()
  46. }
  47. })
  48. app.on('activate', () => {
  49. if (BrowserWindow.getAllWindows().length === 0) {
  50. createWindow()
  51. }
  52. })