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.

59 lines
1.8 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. const url = require('url')
  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(url.format({
  15. pathname: __dirname + '/index.html',
  16. protocol: 'file:',
  17. slashes: true
  18. }))
  19. // Open the DevTools.
  20. mainWindow.webContents.openDevTools()
  21. // Emitted when the window is closed.
  22. mainWindow.on('closed', function () {
  23. // Dereference the window object, usually you would store windows
  24. // in an array if your app supports multi windows, this is the time
  25. // when you should delete the corresponding element.
  26. mainWindow = null
  27. })
  28. }
  29. // This method will be called when Electron has finished
  30. // initialization and is ready to create browser windows.
  31. // Some APIs can only be used after this event occurs.
  32. app.on('ready', createWindow)
  33. // Quit when all windows are closed.
  34. app.on('window-all-closed', function () {
  35. // On OS X it is common for applications and their menu bar
  36. // to stay active until the user quits explicitly with Cmd + Q
  37. if (process.platform !== 'darwin') {
  38. app.quit()
  39. }
  40. })
  41. app.on('activate', function () {
  42. // On OS X it's common to re-create a window in the app when the
  43. // dock icon is clicked and there are no other windows open.
  44. if (mainWindow === null) {
  45. createWindow()
  46. }
  47. })
  48. // In this file you can include the rest of your app's specific main process
  49. // code. You can also put them in separate files and require them here.