main.js 1.7 KB

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