2018-09-14 02:10:51 +10:00
|
|
|
const { app } = require('electron');
|
2016-06-03 12:12:20 +09:00
|
|
|
const net = require('net');
|
|
|
|
|
2016-06-29 09:37:10 -07:00
|
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch';
|
2016-06-03 12:12:20 +09:00
|
|
|
|
|
|
|
process.on('uncaughtException', () => {
|
|
|
|
app.exit(1);
|
|
|
|
});
|
|
|
|
|
2020-02-03 16:43:22 -06:00
|
|
|
app.whenReady().then(() => {
|
2018-10-02 03:56:31 +02:00
|
|
|
const lastArg = process.argv[process.argv.length - 1];
|
2016-06-03 12:12:20 +09:00
|
|
|
const client = net.connect(socketPath);
|
|
|
|
client.once('connect', () => {
|
2022-08-08 01:12:06 -07:00
|
|
|
client.end(lastArg);
|
2016-06-03 12:12:20 +09:00
|
|
|
});
|
|
|
|
client.once('end', () => {
|
2022-08-08 01:12:06 -07:00
|
|
|
if (lastArg === '--first') {
|
|
|
|
// Once without execPath specified
|
|
|
|
app.relaunch({ args: process.argv.slice(1, -1).concat('--second') });
|
|
|
|
} else if (lastArg === '--second') {
|
|
|
|
// And once with execPath specified
|
|
|
|
app.relaunch({ execPath: process.argv[0], args: process.argv.slice(1, -1).concat('--third') });
|
2021-03-07 16:30:43 +09:00
|
|
|
}
|
2016-06-03 12:12:20 +09:00
|
|
|
app.exit(0);
|
|
|
|
});
|
|
|
|
});
|