main.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Modules to control application life and create native browser window
  2. const {
  3. app,
  4. BrowserWindow
  5. } = require('electron')
  6. const config = require('./lib/config.js')
  7. // Keep a global reference of the window object, if you don't, the window will
  8. // be closed automatically when the JavaScript object is garbage collected.
  9. let mainWindow
  10. function createWindow() {
  11. //console.log(app.getAppPath()
  12. // Create the browser window.
  13. mainWindow = new BrowserWindow({
  14. width: 1100,
  15. height: 720,
  16. resizable: false,
  17. webPreferences: {
  18. enableRemoteModule: true,
  19. nodeIntegration: true,
  20. nodeIntegrationInWorker: true
  21. }
  22. })
  23. // and load the index.html of the app.
  24. mainWindow.loadFile('view/login.html')
  25. // Open the DevTools.
  26. if (config.openDevTools === true) {
  27. mainWindow.webContents.openDevTools()
  28. }
  29. // Emitted when the window is closed.
  30. mainWindow.on('closed', function () {
  31. // Dereference the window object, usually you would store windows
  32. // in an array if your app supports multi windows, this is the time
  33. // when you should delete the corresponding element.
  34. mainWindow = null
  35. })
  36. }
  37. // This method will be called when Electron has finished
  38. // initialization and is ready to create browser windows.
  39. // Some APIs can only be used after this event occurs.
  40. app.on('ready', createWindow)
  41. // Quit when all windows are closed.
  42. app.on('window-all-closed', function () {
  43. // On OS X it is common for applications and their menu bar
  44. // to stay active until the user quits explicitly with Cmd + Q
  45. //if (process.platform !== 'darwin') {
  46. app.quit()
  47. //}
  48. })
  49. app.on('activate', function () {
  50. // On OS X it's common to re-create a window in the app when the
  51. // dock icon is clicked and there are no other windows open.
  52. if (mainWindow === null) {
  53. createWindow()
  54. }
  55. })
  56. // In this file you can include the rest of your app's specific main process
  57. // code. You can also put them in separate files and require them here.