main.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Quit when all windows are closed.
  11. app.on('window-all-closed', function () {
  12. // On OS X it is common for applications and their menu bar
  13. // to stay active until the user quits explicitly with Cmd + Q
  14. if (process.platform !== 'darwin') {
  15. app.quit();
  16. }
  17. });
  18. app.on('activate', function () {
  19. // On OS X it's common to re-create a window in the app when the
  20. // dock icon is clicked and there are no other windows open.
  21. if (mainWindow === null) {
  22. app.emit('ready');
  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', function() {
  28. // Create the browser window.
  29. mainWindow = new BrowserWindow({width: 800, height: 600});
  30. // and load the index.html of the app.
  31. mainWindow.loadURL('file://' + __dirname + '/index.html');
  32. // Open the DevTools.
  33. mainWindow.webContents.openDevTools();
  34. // Emitted when the window is closed.
  35. mainWindow.on('closed', function() {
  36. // Dereference the window object, usually you would store windows
  37. // in an array if your app supports multi windows, this is the time
  38. // when you should delete the corresponding element.
  39. mainWindow = null;
  40. });
  41. });