main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const { app, BrowserWindow } = require('electron');
  2. const path = require('path');
  3. const { program } = require('commander');
  4. program.version('0.0.1');
  5. program
  6. .option('-s, --src', 'Load the file from src folder instead of the app folder');
  7. program.parse(process.argv);
  8. const folder = program.src ? 'src' : 'app';
  9. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
  10. if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  11. app.quit();
  12. }
  13. const createWindow = () => {
  14. // Create the browser window.
  15. const mainWindow = new BrowserWindow({
  16. width: 800,
  17. height: 600,
  18. });
  19. // and load the index.html of the app.
  20. mainWindow.loadFile(path.join(__dirname, `/${folder}/index.html`));
  21. // Open the DevTools.
  22. mainWindow.webContents.openDevTools();
  23. };
  24. // This method will be called when Electron has finished
  25. // initialization and is ready to create browser windows.
  26. // Some APIs can only be used after this event occurs.
  27. app.on('ready', createWindow);
  28. // Quit when all windows are closed.
  29. app.on('window-all-closed', () => {
  30. // On OS X it is common for applications and their menu bar
  31. // to stay active until the user quits explicitly with Cmd + Q
  32. if (process.platform !== 'darwin') {
  33. app.quit();
  34. }
  35. });
  36. app.on('activate', () => {
  37. // On OS X it's common to re-create a window in the app when the
  38. // dock icon is clicked and there are no other windows open.
  39. if (BrowserWindow.getAllWindows().length === 0) {
  40. createWindow();
  41. }
  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 import them here.