fix: second-instance additionalData parameter (#31661)

* test: second-instance additionalData parameter

* Fix posix implementation
This commit is contained in:
Raymond Zhao
2021-11-04 01:14:09 -07:00
committed by GitHub
parent 86f6285299
commit 9e0e04da25
4 changed files with 110 additions and 29 deletions

View File

@@ -1,10 +1,13 @@
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
});
const obj = {
let obj = {
level: 1,
testkey: 'testvalue1',
inner: {
@@ -12,7 +15,15 @@ const obj = {
testkey: 'testvalue2'
}
};
const gotTheLock = app.requestSingleInstanceLock(obj);
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(() => {

View File

@@ -6,9 +6,9 @@ app.whenReady().then(() => {
const gotTheLock = app.requestSingleInstanceLock();
app.on('second-instance', (event, args, workingDirectory, data) => {
app.on('second-instance', (event, args, workingDirectory) => {
setImmediate(() => {
console.log([JSON.stringify(args), JSON.stringify(data)].join('||'));
console.log(JSON.stringify(args));
app.exit(0);
});
});