You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB

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