main.js 629 B

12345678910111213141516171819202122
  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(String(lastArg === '--second'));
  12. });
  13. client.once('end', () => {
  14. if (lastArg !== '--second') {
  15. app.relaunch({ args: process.argv.slice(1).concat('--second') });
  16. }
  17. app.exit(0);
  18. });
  19. });