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.

53 lines
1.8 KiB

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