electronStart.js 1.6 KB

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