index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { app, BrowserWindow } from 'electron'
  2. /**
  3. * Set `__static` path to static files in production
  4. * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
  5. */
  6. if (process.env.NODE_ENV !== 'development') {
  7. global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
  8. }
  9. let mainWindow
  10. const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `file://${__dirname}/index.html`
  11. function createWindow () {
  12. /**
  13. * Initial window options
  14. */
  15. mainWindow = new BrowserWindow({
  16. width: 1000,
  17. height: 563,
  18. show:false,
  19. useContentSize: true,
  20. webPreferences: {
  21. // 允许跨域
  22. webSecurity: false,
  23. // 渲染进程是否使用node
  24. nodeIntegration: true
  25. },
  26. })
  27. mainWindow.loadURL(winURL)
  28. // mainWindow.webContents.openDevTools();
  29. mainWindow.once('ready-to-show', () => {
  30. mainWindow.show()
  31. })
  32. mainWindow.on('closed', () => {
  33. mainWindow = null
  34. })
  35. }
  36. app.on('ready', createWindow)
  37. app.on('window-all-closed', () => {
  38. if (process.platform !== 'darwin') {
  39. app.quit()
  40. }
  41. })
  42. app.on('activate', () => {
  43. if (mainWindow === null) {
  44. createWindow()
  45. }
  46. })