main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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: 1200,
  17. height: 720,
  18. });
  19. // and load the index.html of the app.
  20. mainWindow.loadFile(path.join(__dirname, `/${folder}/index.html`));
  21. };
  22. // This method will be called when Electron has finished
  23. // initialization and is ready to create browser windows.
  24. // Some APIs can only be used after this event occurs.
  25. app.on('ready', createWindow);
  26. // Quit when all windows are closed.
  27. app.on('window-all-closed', () => {
  28. // On OS X it is common for applications and their menu bar
  29. // to stay active until the user quits explicitly with Cmd + Q
  30. if (process.platform !== 'darwin') {
  31. app.quit();
  32. }
  33. });
  34. app.on('activate', () => {
  35. // On OS X it's common to re-create a window in the app when the
  36. // dock icon is clicked and there are no other windows open.
  37. if (BrowserWindow.getAllWindows().length === 0) {
  38. createWindow();
  39. }
  40. });
  41. // In this file you can include the rest of your app's specific main process
  42. // code. You can also put them in separate files and import them here.