feat: Add data parameter to app.requestSingleInstanceLock()
(#30891)
* WIP * Use serialization * Rebase windows impl of new app requestSingleInstanceLock parameter * Fix test * Implement posix side * Add backwards compatibility test * Apply PR feedback Windows * Fix posix impl * Switch mac impl back to vector * Refactor Windows impl * Use vectors, inline make_span * Use blink converter * fix: ownership across sequences * Fix upstream merge from Chromium Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
parent
5592652504
commit
db0a152bc1
9 changed files with 442 additions and 22 deletions
|
@ -483,6 +483,7 @@ Returns:
|
|||
* `event` Event
|
||||
* `argv` String[] - An array of the second instance's command line arguments
|
||||
* `workingDirectory` String - The second instance's working directory
|
||||
* `additionalData` unknown - A JSON object of additional data passed from the second instance
|
||||
|
||||
This event will be emitted inside the primary instance of your application
|
||||
when a second instance has been executed and calls `app.requestSingleInstanceLock()`.
|
||||
|
@ -931,6 +932,8 @@ app.setJumpList([
|
|||
|
||||
### `app.requestSingleInstanceLock()`
|
||||
|
||||
* `additionalData` unknown (optional) - A JSON object containing additional data to send to the first instance.
|
||||
|
||||
Returns `Boolean`
|
||||
|
||||
The return value of this method indicates whether or not this instance of your
|
||||
|
@ -956,12 +959,16 @@ starts:
|
|||
const { app } = require('electron')
|
||||
let myWindow = null
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
const additionalData = { myKey: 'myValue' }
|
||||
const gotTheLock = app.requestSingleInstanceLock(additionalData)
|
||||
|
||||
if (!gotTheLock) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
|
||||
// Print out data received from the second instance.
|
||||
console.log(additionalData)
|
||||
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (myWindow) {
|
||||
if (myWindow.isMinimized()) myWindow.restore()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue