main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (program.src) {
  9. console.log('coucou');
  10. app.quit();
  11. }
  12. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
  13. if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  14. app.quit();
  15. }
  16. const createWindow = () => {
  17. // Create the browser window.
  18. const mainWindow = new BrowserWindow({
  19. width: 800,
  20. height: 600,
  21. });
  22. // and load the index.html of the app.
  23. mainWindow.loadFile(path.join(__dirname, '/src/index.html'));
  24. // Open the DevTools.
  25. mainWindow.webContents.openDevTools();
  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', () => {
  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', () => {
  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 (BrowserWindow.getAllWindows().length === 0) {
  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 import them here.