index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { app, BrowserWindow } from 'electron'
  2. import path from 'path'
  3. /**
  4. * Set `__static` path to static files in production
  5. * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
  6. */
  7. if (process.env.NODE_ENV !== 'development') {
  8. global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
  9. }
  10. let mainWindow
  11. const winURL = process.env.NODE_ENV === 'development'
  12. ? `http://localhost:9080`
  13. : `file://${__dirname}/index.html`
  14. function createWindow () {
  15. /**
  16. * Initial window options
  17. */
  18. mainWindow = new BrowserWindow({
  19. height: 563,
  20. useContentSize: true,
  21. width: 1000
  22. })
  23. mainWindow.loadURL(winURL)
  24. mainWindow.on('closed', () => {
  25. mainWindow = null
  26. })
  27. }
  28. let serverpath = process.env.NODE_ENV === 'development'
  29. ? path.join(__dirname, '..', '..', 'static', 'server', 'bin', 'www.js')
  30. : `${app.getAppPath()}/dist/electron/static/server/bin/www`
  31. app.server = require("child_process")
  32. .fork(serverpath,
  33. [], {
  34. stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
  35. silent: false
  36. })
  37. app.server.stderr.pipe(process.stderr)
  38. app.server.stdout.pipe(process.stdout)
  39. console.log("backend now running on : " + app.server.pid)
  40. app.on('ready', createWindow)
  41. app.on('window-all-closed', () => {
  42. if (process.platform !== 'darwin') {
  43. app.quit()
  44. }
  45. })
  46. app.on('activate', () => {
  47. if (mainWindow === null) {
  48. createWindow()
  49. }
  50. })
  51. /**
  52. * Auto Updater
  53. *
  54. * Uncomment the following code below and install `electron-updater` to
  55. * support auto updating. Code Signing with a valid certificate is required.
  56. * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
  57. */
  58. /*
  59. import { autoUpdater } from 'electron-updater'
  60. autoUpdater.on('update-downloaded', () => {
  61. autoUpdater.quitAndInstall()
  62. })
  63. app.on('ready', () => {
  64. if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
  65. })
  66. */