main.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const { app, BrowserWindow } = require('electron');
  2. const path = require('path');
  3. const url = require('url');
  4. const isLocal = process.argv[process.argv.length - 1] === 'local';
  5. const extDir = isLocal ? '../build/production/saas' : 'dist';
  6. let mainWindow;
  7. function createWindow () {
  8. mainWindow = new BrowserWindow({ width: 1280, height: 720, show: false });
  9. mainWindow.once('ready-to-show', function(){
  10. mainWindow.maximize();
  11. mainWindow.show();
  12. });
  13. mainWindow.loadURL(url.format({
  14. pathname: path.join(__dirname, extDir + '/index.html'),
  15. protocol: 'file:',
  16. slashes: true
  17. }));
  18. if (isLocal) {
  19. mainWindow.webContents.openDevTools();
  20. }
  21. mainWindow.on('closed', function () {
  22. mainWindow = null;
  23. });
  24. }
  25. app.on('ready', createWindow);
  26. // Quit when all windows are closed, except for Mac users
  27. app.on('window-all-closed', function () {
  28. if (process.platform !== 'darwin') {
  29. app.quit()
  30. }
  31. });
  32. app.on('activate', function () {
  33. if (mainWindow === null) {
  34. createWindow();
  35. }
  36. });