main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const electron = require('electron');
  3. // Module to control application life.
  4. const app = electron.app;
  5. // Module to create native browser window.
  6. const BrowserWindow = electron.BrowserWindow;
  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. // Create the browser window.
  12. mainWindow = new BrowserWindow({width: 800, height: 600});
  13. // and load the index.html of the app.
  14. mainWindow.loadURL('file://' + __dirname + '/index.html');
  15. // Open the DevTools.
  16. mainWindow.webContents.openDevTools();
  17. // Emitted when the window is closed.
  18. mainWindow.on('closed', function() {
  19. // Dereference the window object, usually you would store windows
  20. // in an array if your app supports multi windows, this is the time
  21. // when you should delete the corresponding element.
  22. mainWindow = null;
  23. });
  24. }
  25. // This method will be called when Electron has finished
  26. // initialization and is ready to create browser windows.
  27. app.on('ready', createWindow);
  28. // Quit when all windows are closed.
  29. app.on('window-all-closed', function () {
  30. // On OS X it is common for applications and their menu bar
  31. // to stay active until the user quits explicitly with Cmd + Q
  32. if (process.platform !== 'darwin') {
  33. app.quit();
  34. }
  35. });
  36. app.on('activate', function () {
  37. // On OS X 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) {
  40. createWindow();
  41. }
  42. });