revert: add first-instance-ack event to the app.requestSingleInstanceLock()
flow (#34297)
fix: revert "feat: add first-instance-ack event to the `app.requestSingleInstanceLock()` flow"
This commit is contained in:
parent
ff13fa8f0a
commit
38c21b7aca
8 changed files with 400 additions and 862 deletions
41
spec/fixtures/api/singleton-data/main.js
vendored
41
spec/fixtures/api/singleton-data/main.js
vendored
|
@ -1,17 +1,11 @@
|
|||
const { app } = require('electron');
|
||||
|
||||
app.whenReady().then(() => {
|
||||
console.log('started'); // ping parent
|
||||
});
|
||||
|
||||
// Send data from the second instance to the first instance.
|
||||
const sendAdditionalData = app.commandLine.hasSwitch('send-data');
|
||||
|
||||
// Prevent the default behaviour of second-instance, which sends back an empty ack.
|
||||
const preventDefault = app.commandLine.hasSwitch('prevent-default');
|
||||
|
||||
// Send an object back for the ack rather than undefined.
|
||||
const sendAck = app.commandLine.hasSwitch('send-ack');
|
||||
app.whenReady().then(() => {
|
||||
console.log('started'); // ping parent
|
||||
});
|
||||
|
||||
let obj = {
|
||||
level: 1,
|
||||
|
@ -21,45 +15,20 @@ let obj = {
|
|||
testkey: 'testvalue2'
|
||||
}
|
||||
};
|
||||
let ackObj = {
|
||||
level: 1,
|
||||
testkey: 'acktestvalue1',
|
||||
inner: {
|
||||
level: 2,
|
||||
testkey: 'acktestvalue2'
|
||||
}
|
||||
};
|
||||
|
||||
if (app.commandLine.hasSwitch('data-content')) {
|
||||
obj = JSON.parse(app.commandLine.getSwitchValue('data-content'));
|
||||
if (obj === 'undefined') {
|
||||
obj = undefined;
|
||||
}
|
||||
}
|
||||
if (app.commandLine.hasSwitch('ack-content')) {
|
||||
ackObj = JSON.parse(app.commandLine.getSwitchValue('ack-content'));
|
||||
if (ackObj === 'undefined') {
|
||||
ackObj = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
app.on('first-instance-ack', (event, additionalData) => {
|
||||
console.log(JSON.stringify(additionalData));
|
||||
});
|
||||
|
||||
const gotTheLock = sendAdditionalData
|
||||
? app.requestSingleInstanceLock(obj) : app.requestSingleInstanceLock();
|
||||
|
||||
app.on('second-instance', (event, args, workingDirectory, data, ackCallback) => {
|
||||
if (preventDefault) {
|
||||
event.preventDefault();
|
||||
}
|
||||
app.on('second-instance', (event, args, workingDirectory, data) => {
|
||||
setImmediate(() => {
|
||||
console.log([JSON.stringify(args), JSON.stringify(data)].join('||'));
|
||||
sendAck ? ackCallback(ackObj) : ackCallback();
|
||||
setImmediate(() => {
|
||||
app.exit(0);
|
||||
});
|
||||
app.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue