main.js 2.0 KB

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