electron.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const {
  2. app,
  3. BrowserWindow,
  4. BrowserView,
  5. Tray,
  6. Menu,
  7. nativeImage,
  8. screen
  9. } = require('electron')
  10. const { resolve } = require('path')
  11. let tray
  12. function createWindow () {
  13. const mainScreen = screen.getPrimaryDisplay()
  14. const menuBarHeight = mainScreen.workArea.y
  15. const mainWindow = new BrowserWindow({
  16. width: 1000,
  17. height: 600, // 设置打开的窗口大小
  18. useContentSize: true,
  19. enableLargerThanScreen: true,
  20. autoHideMenuBar: true,
  21. icon: 'logo.png',
  22. frame: true, // 显示mac 上顶部的状态栏
  23. webPreferences: {
  24. // contextIsolation: false,
  25. // worldSafeExecuteJavaScript:a flse,
  26. // webSecurity: false,
  27. nodeIntegration: true // 是否集成node.js,解决require is not defined问题
  28. // nodeIntegrationInWorker: true,
  29. // webviewTag: true, // 解决webview无法显示问题
  30. // enableRemoteModule: true,
  31. }
  32. })
  33. // mainWindow.setIcon('https://agent-crm.luojigou.vip/crm-api//20210323/logo_icon.png')
  34. // console.log(resolve(process.cwd(), 'dist/index.html'))
  35. // mainWindow.loadFile(resolve(process.cwd(), 'dist/index.html'))
  36. const view = new BrowserView() // new出对象
  37. mainWindow.setBrowserView(view) // 在主窗口中设置view可用
  38. view.setBounds({ x: 0, y: 0, width: 1000, height: 600 }) // 定义view的具体样式和位置
  39. view.setAutoResize({ width: true, height: true })
  40. view.useContentSize = true
  41. // 解决mac 顶部的菜单栏高度显示问题
  42. // const marginTopDiv = document.createElement('div')
  43. // marginTopDiv.style.height = `${menuBarHeight}px`
  44. // marginTopDiv.style.width = '100%'
  45. // document.body.appendChild(marginTopDiv)
  46. view.webContents.loadURL('http://cloudlink.jiaolongcloud.com') // wiew载入的页面
  47. }
  48. app.whenReady().then(() => {
  49. const icon = nativeImage.createFromPath('./logo.png')
  50. tray = new Tray(icon)
  51. const contextMenu = Menu.buildFromTemplate([])
  52. tray.setContextMenu(contextMenu)
  53. tray.setToolTip('蛟龙云')
  54. tray.setTitle('蛟龙云')
  55. createWindow()
  56. })
  57. app.on('window-all-closed', () => {
  58. if (process.platform !== 'darwin') {
  59. app.quit()
  60. }
  61. })
  62. app.on('activate', () => {
  63. if (BrowserWindow.getAllWindows().length === 0) {
  64. createWindow()
  65. }
  66. })