index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { app, BrowserWindow,screen } from 'electron'
  2. import express from "express"
  3. const electron = require('electron')
  4. const ipc = electron.ipcMain
  5. /**
  6. * Set `__static` path to static files in production
  7. * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
  8. */
  9. if (process.env.NODE_ENV !== 'development') {
  10. global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
  11. }
  12. let mainWindow
  13. const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `http://localhost:8888/index.html`
  14. app.commandLine.appendSwitch('ppapi-flash-path',app.getPath('pepperFlashSystemPlugin'))
  15. function createWindow () {
  16. let size = screen.getPrimaryDisplay().workAreaSize
  17. let width = parseInt(size.width)
  18. let height = parseInt(size.height)
  19. /**
  20. * Initial window options
  21. */
  22. mainWindow = new BrowserWindow({
  23. width: width,
  24. height: height,
  25. show:false,
  26. titleBarStyle:'hiddenInset',
  27. autoHideMenuBar: true,
  28. webPreferences: {
  29. // 使用插件
  30. plugins: true,
  31. // 允许跨域
  32. webSecurity: false,
  33. // 渲染进程是否使用node
  34. nodeIntegration: true
  35. },
  36. })
  37. mainWindow.loadURL(winURL)
  38. //进入软件即开启全屏
  39. mainWindow.setFullScreen(true)
  40. // 打开开发者工具
  41. // mainWindow.webContents.openDevTools();
  42. mainWindow.once('ready-to-show', () => {
  43. mainWindow.show()
  44. })
  45. mainWindow.on('closed', () => {
  46. mainWindow = null
  47. })
  48. if (process.env.NODE_ENV === "production") {
  49. localServer()
  50. }
  51. }
  52. app.on('ready', createWindow)
  53. app.on('window-all-closed', () => {
  54. if (process.platform !== 'darwin') {
  55. app.quit()
  56. }
  57. })
  58. app.on('activate', () => {
  59. if (mainWindow === null) {
  60. createWindow()
  61. }
  62. })
  63. // 最小化窗口
  64. ipc.on('window-min',function(){
  65. mainWindow.minimize()
  66. })
  67. // 关闭窗口
  68. ipc.on('window-close',function() {
  69. mainWindow.close()
  70. })
  71. function localServer() {
  72. let server = express()
  73. server.use(express.static(__dirname))
  74. server.listen(8888)
  75. }