electron.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 path = require('path');
  7. const url = require('url');
  8. const isDev = require('electron-is-dev');
  9. // Keep a global reference of the window object, if you don't, the window will
  10. // be closed automatically when the JavaScript object is garbage collected.
  11. let mainWindow;
  12. function createWindow() {
  13. // Create the browser window.
  14. mainWindow = new BrowserWindow({width: 1280, height: 800});
  15. // and load the index.html of the app.
  16. mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`);
  17. // Open the DevTools.
  18. mainWindow.menuBarVisible=false;
  19. // Emitted when the window is closed.
  20. mainWindow.on('closed', function () {
  21. // Dereference the window object, usually you would store windows
  22. // in an array if your app supports multi windows, this is the time
  23. // when you should delete the corresponding element.
  24. mainWindow = null
  25. })
  26. }
  27. // This method will be called when Electron has finished
  28. // initialization and is ready to create browser windows.
  29. // Some APIs can only be used after this event occurs.
  30. app.on('ready', createWindow);
  31. // Quit when all windows are closed.
  32. app.on('window-all-closed', function () {
  33. // On OS X it is common for applications and their menu bar
  34. // to stay active until the user quits explicitly with Cmd + Q
  35. if (process.platform !== 'darwin') {
  36. app.quit()
  37. }
  38. });
  39. app.on('activate', function () {
  40. // On OS X it's common to re-create a window in the app when the
  41. // dock icon is clicked and there are no other windows open.
  42. if (mainWindow === null) {
  43. createWindow()
  44. }
  45. });
  46. // In this file you can include the rest of your app's specific main process
  47. // code. You can also put them in separate files and require them here.