main.js 2.0 KB

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