forked from electron/electron
/
main.js
37 lines (31 loc) · 866 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { app } = require('electron');
// Send data from the second instance to the first instance.
const sendAdditionalData = app.commandLine.hasSwitch('send-data');
app.whenReady().then(() => {
console.log('started'); // ping parent
});
let obj = {
level: 1,
testkey: 'testvalue1',
inner: {
level: 2,
testkey: 'testvalue2'
}
};
if (app.commandLine.hasSwitch('data-content')) {
obj = JSON.parse(app.commandLine.getSwitchValue('data-content'));
if (obj === 'undefined') {
obj = undefined;
}
}
const gotTheLock = sendAdditionalData
? app.requestSingleInstanceLock(obj) : app.requestSingleInstanceLock();
app.on('second-instance', (event, args, workingDirectory, data) => {
setImmediate(() => {
console.log([JSON.stringify(args), JSON.stringify(data)].join('||'));
app.exit(0);
});
});
if (!gotTheLock) {
app.exit(1);
}