electron/spec/fixtures/api/relaunch/main.js

24 lines
624 B
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
const { app } = require('electron');
const net = require('net');
2016-06-03 03:12:20 +00:00
2020-03-20 20:28:31 +00:00
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch';
2016-06-03 03:12:20 +00:00
process.on('uncaughtException', () => {
2020-03-20 20:28:31 +00:00
app.exit(1);
});
2016-06-03 03:12:20 +00:00
app.whenReady().then(() => {
2020-03-20 20:28:31 +00:00
const lastArg = process.argv[process.argv.length - 1];
const client = net.connect(socketPath);
2016-06-03 03:12:20 +00:00
client.once('connect', () => {
2020-03-20 20:28:31 +00:00
client.end(String(lastArg === '--second'));
});
2016-06-03 03:12:20 +00:00
client.once('end', () => {
2020-03-20 20:28:31 +00:00
app.exit(0);
});
2016-06-03 03:12:20 +00:00
if (lastArg !== '--second') {
2020-03-20 20:28:31 +00:00
app.relaunch({ args: process.argv.slice(1).concat('--second') });
2016-06-03 03:12:20 +00:00
}
2020-03-20 20:28:31 +00:00
});