main.js 602 B

123456789101112131415161718192021222324
  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.once('ready', () => {
  8. let 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. app.exit(0)
  15. })
  16. if (lastArg !== '--second') {
  17. app.relaunch({args: process.argv.slice(1).concat('--second')})
  18. }
  19. })