Skip to content

Commit

Permalink
Add back missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 committed Nov 8, 2021
1 parent 6c457b1 commit 9576d74
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions docs/api/app.md
Expand Up @@ -501,9 +501,14 @@ second instance during the `app.requestSingleInstanceLock()` flow.
This callback can be used for cases where the second instance
needs to obtain additional information from the first instance
before quitting.
In order to call the callback, `event.preventDefault()` must be called
Then, the `ackCallback` callback can be called.

Currently, the limit on the message size is kMaxMessageLength,
or around 32kB. To be safe, keep the amount of data passed to 31kB at most.

In order to call the callback, `event.preventDefault()` must be called, first.
If the callback is not called in either case, `null` will be sent back.
If `event.preventDefault()` is not called, but `ackCallback` is called
by the user in the event, then the behaviour is undefined.

This event is guaranteed to be emitted after the `ready` event of `app`
gets emitted.
Expand Down Expand Up @@ -978,21 +983,33 @@ starts:
const { app } = require('electron')
let myWindow = null

app.on('first-instance-ack', (event, additionalData) => {
// Print out the ack received from the first instance.
// Note this event handler must come before the requestSingleInstanceLock call.
// Expected output: '{"myAckKey":"myAckValue"}'
console.log(JSON.stringify(additionalData))
})

const additionalData = { myKey: 'myValue' }
const gotTheLock = app.requestSingleInstanceLock(additionalData)

if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
// We must call preventDefault if we're sending back data.
event.preventDefault()
// Print out data received from the second instance.
console.log(additionalData)
// Expected output: '{"myKey":"myValue"}'
console.log(JSON.stringify(additionalData))

// Someone tried to run a second instance, we should focus our window.
if (myWindow) {
if (myWindow.isMinimized()) myWindow.restore()
myWindow.focus()
}
const ackData = { myAckKey: 'myAckValue' }
ackCallback(ackData)
})

// Create myWindow, load the rest of the app, etc...
Expand Down

0 comments on commit 9576d74

Please sign in to comment.