electron/spec/fixtures/api/singleton-data/main.js
Samuel Attard 74af96da16
build: update some build dependencies (#43882)
* build: update some build dependencies

* build: fix eslint issues after updating

* build: disable ts check on busted js example

* build: update internal types for stricter event handling

* restore url.parse behavior

* fix typing issues

* sigh

* build: update easy deps

* build: skip woa engines check
2024-09-26 00:12:11 -07:00

38 lines
868 B
JavaScript

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);
}