Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 committed Oct 18, 2021
1 parent c730e0d commit fa80609
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/api/app.md
Expand Up @@ -484,6 +484,7 @@ 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 accepts data to pass 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 @@ -495,12 +496,23 @@ 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:** In order to call the callback, first call `preventDefault` on the `event` object. Then, call the callback with the data to pass back to the second instance. Otherwise, null will be sent back.

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
4 changes: 2 additions & 2 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -1086,7 +1086,7 @@ void App::OnFirstInstanceAck(
v8::HandleScope handle_scope(isolate);
base::Value data_to_send;
if (first_instance_data) {
// Don't send back the local directly, because it might be empty
// Don't send back the local directly, because it might be empty.
v8::Local<v8::Value> data_local;
data_local = DeserializeV8Value(isolate, *first_instance_data);
if (!data_local.IsEmpty()) {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ void App::OnSecondInstance(
bool prevent_default =
Emit("second-instance", cmd.argv(), cwd, data_value, cb);
if (!prevent_default) {
// Call the callback ourselves and send back nothing.
// Call the callback ourselves, and send back nothing.
ack_callback.Run(nullptr);
}
}
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_app.h
Expand Up @@ -196,7 +196,6 @@ class App : public ElectronBrowserClient::Delegate,
const ProcessSingleton::NotificationAckCallback& ack_callback);
bool HasSingleInstanceLock() const;
bool RequestSingleInstanceLock(gin::Arguments* args);
v8::Local<v8::Promise> WaitSingleInstanceResponse(gin::Arguments* args);
void ReleaseSingleInstanceLock();
bool Relaunch(gin::Arguments* args);
void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);
Expand Down

0 comments on commit fa80609

Please sign in to comment.