main.js 835 B

1234567891011121314151617181920212223242526
  1. const { app } = require('electron');
  2. const net = require('net');
  3. const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch';
  4. process.on('uncaughtException', () => {
  5. app.exit(1);
  6. });
  7. app.whenReady().then(() => {
  8. const lastArg = process.argv[process.argv.length - 1];
  9. const client = net.connect(socketPath);
  10. client.once('connect', () => {
  11. client.end(lastArg);
  12. });
  13. client.once('end', () => {
  14. if (lastArg === '--first') {
  15. // Once without execPath specified
  16. app.relaunch({ args: process.argv.slice(1, -1).concat('--second') });
  17. } else if (lastArg === '--second') {
  18. // And once with execPath specified
  19. app.relaunch({ execPath: process.argv[0], args: process.argv.slice(1, -1).concat('--third') });
  20. }
  21. app.exit(0);
  22. });
  23. });