From fa806092fc8978e606ac973f87be802dd1cf9a96 Mon Sep 17 00:00:00 2001 From: Raymond Zhao Date: Mon, 18 Oct 2021 12:33:15 -0700 Subject: [PATCH] Add docs --- docs/api/app.md | 12 ++++++++++++ shell/browser/api/electron_api_app.cc | 4 ++-- shell/browser/api/electron_api_app.h | 1 - 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 005ab2fe94756..469356b0f4c0d 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -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()`. @@ -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: diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index fe8b3cc1a9588..4073b19c03361 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -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 data_local; data_local = DeserializeV8Value(isolate, *first_instance_data); if (!data_local.IsEmpty()) { @@ -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); } } diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index 3a81a4868f302..cc03e8f0d60db 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -196,7 +196,6 @@ class App : public ElectronBrowserClient::Delegate, const ProcessSingleton::NotificationAckCallback& ack_callback); bool HasSingleInstanceLock() const; bool RequestSingleInstanceLock(gin::Arguments* args); - v8::Local WaitSingleInstanceResponse(gin::Arguments* args); void ReleaseSingleInstanceLock(); bool Relaunch(gin::Arguments* args); void DisableHardwareAcceleration(gin_helper::ErrorThrower thrower);