Skip to content

Commit

Permalink
revert: add first-instance-ack event to the app.requestSingleInstance…
Browse files Browse the repository at this point in the history
…Lock() flow (#34312)

fix: revert "feat: add first-instance-ack event to the `app.requestSingleInstanceLock()` flow (#34295)

* Revert "fix: requestSingleInstanceLock API ConnectNamedPipe sometimes hangs program (#33778)"

This reverts commit ffb8749.

* fix: revert "feat: add first-instance-ack event to the `app.requestSingleInstanceLock()` flow"

* chore: update patch
  • Loading branch information
VerteDinde committed May 23, 2022
1 parent cc4565b commit 23c18be
Show file tree
Hide file tree
Showing 8 changed files with 401 additions and 862 deletions.
40 changes: 2 additions & 38 deletions docs/api/app.md
Expand Up @@ -484,7 +484,6 @@ Returns:
* `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
* `ackCallback` unknown - A function that can be used to send data back to 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()`.
Expand All @@ -496,35 +495,12 @@ non-minimized.

**Note:** If the second instance is started by a different user than the first, the `argv` array will not include the arguments.

**Note:** `ackCallback` allows the user to send data back to the
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.

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.

**Note:** Extra command line arguments might be added by Chromium,
such as `--original-process-start-time`.

### Event: 'first-instance-ack'

Returns:

* `event` Event
* `additionalData` unknown - A JSON object of additional data passed from the first instance, in response to the first instance's `second-instance` event.

This event will be emitted within the second instance during the call to `app.requestSingleInstanceLock()`, when the first instance calls the `ackCallback` provided by the `second-instance` event handler.

## Methods

The `app` object has the following methods:
Expand Down Expand Up @@ -985,33 +961,21 @@ 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, ackCallback) => {
// We must call preventDefault if we're sending back data.
event.preventDefault()
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
// Print out data received from the second instance.
// Expected output: '{"myKey":"myValue"}'
console.log(JSON.stringify(additionalData))
console.log(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
2 changes: 1 addition & 1 deletion patches/chromium/.patches
Expand Up @@ -102,12 +102,12 @@ chore_do_not_use_chrome_windows_in_cryptotoken_webrequestsender.patch
process_singleton.patch
fix_expose_decrementcapturercount_in_web_contents_impl.patch
add_ui_scopedcliboardwriter_writeunsaferawdata.patch
feat_add_data_parameter_to_processsingleton.patch
mas_gate_private_enterprise_APIs.patch
load_v8_snapshot_in_browser_process.patch
fix_patch_out_permissions_checks_in_exclusive_access.patch
fix_aspect_ratio_with_max_size.patch
fix_dont_delete_SerialPortManager_on_main_thread.patch
feat_add_data_transfer_to_requestsingleinstancelock.patch
fix_crash_when_saving_edited_pdf_files.patch
port_autofill_colors_to_the_color_pipeline.patch
build_disable_partition_alloc_on_mac.patch
Expand Down

0 comments on commit 23c18be

Please sign in to comment.