feat: allow macOS apps to set activation policies (#21983)
This commit is contained in:
parent
3341a2c3b4
commit
303ca10846
5 changed files with 42 additions and 0 deletions
|
@ -994,6 +994,17 @@ Updates the current activity if its type matches `type`, merging the entries fro
|
||||||
|
|
||||||
Changes the [Application User Model ID][app-user-model-id] to `id`.
|
Changes the [Application User Model ID][app-user-model-id] to `id`.
|
||||||
|
|
||||||
|
### `app.setActivationPolicy(policy)` _macOS_
|
||||||
|
|
||||||
|
* `policy` String - Can be 'regular', 'accessory', or 'prohibited'.
|
||||||
|
|
||||||
|
Sets the activation policy for a given app.
|
||||||
|
|
||||||
|
Activation policy types:
|
||||||
|
* 'regular' - The application is an ordinary app that appears in the Dock and may have a user interface.
|
||||||
|
* 'accessory' - The application doesn’t appear in the Dock and doesn’t have a menu bar, but it may be activated programmatically or by clicking on one of its windows.
|
||||||
|
* 'prohibited' - The application doesn’t appear in the Dock and may not create windows or be activated.
|
||||||
|
|
||||||
### `app.importCertificate(options, callback)` _Linux_
|
### `app.importCertificate(options, callback)` _Linux_
|
||||||
|
|
||||||
* `options` Object
|
* `options` Object
|
||||||
|
|
|
@ -1459,6 +1459,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
||||||
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
|
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
|
||||||
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
||||||
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
||||||
|
.SetMethod("setActivationPolicy", &App::SetActivationPolicy)
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("setAboutPanelOptions",
|
.SetMethod("setAboutPanelOptions",
|
||||||
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
||||||
|
|
|
@ -201,6 +201,8 @@ class App : public ElectronBrowserClient::Delegate,
|
||||||
bool CanBrowserClientUseCustomSiteInstance();
|
bool CanBrowserClientUseCustomSiteInstance();
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
void SetActivationPolicy(gin_helper::ErrorThrower thrower,
|
||||||
|
const std::string& policy);
|
||||||
bool MoveToApplicationsFolder(gin_helper::ErrorThrower, gin::Arguments* args);
|
bool MoveToApplicationsFolder(gin_helper::ErrorThrower, gin::Arguments* args);
|
||||||
bool IsInApplicationsFolder();
|
bool IsInApplicationsFolder();
|
||||||
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetDockAPI(v8::Isolate* isolate);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// Use of this source code is governed by the MIT license that can be
|
// Use of this source code is governed by the MIT license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "shell/browser/api/electron_api_app.h"
|
#include "shell/browser/api/electron_api_app.h"
|
||||||
#include "shell/browser/electron_paths.h"
|
#include "shell/browser/electron_paths.h"
|
||||||
|
@ -32,6 +34,24 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::SetActivationPolicy(gin_helper::ErrorThrower thrower,
|
||||||
|
const std::string& policy) {
|
||||||
|
NSApplicationActivationPolicy activation_policy;
|
||||||
|
if (policy == "accessory") {
|
||||||
|
activation_policy = NSApplicationActivationPolicyAccessory;
|
||||||
|
} else if (policy == "prohibited") {
|
||||||
|
activation_policy = NSApplicationActivationPolicyProhibited;
|
||||||
|
} else if (policy == "regular") {
|
||||||
|
activation_policy = NSApplicationActivationPolicyRegular;
|
||||||
|
} else {
|
||||||
|
thrower.ThrowError("Invalid activation policy: must be one of 'regular', "
|
||||||
|
"'accessory', or 'prohibited'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[NSApp setActivationPolicy:activation_policy];
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -202,6 +202,14 @@ describe('app module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('app.setActivationPolicy', () => {
|
||||||
|
it('throws an error on invalid application policies', () => {
|
||||||
|
expect(() => {
|
||||||
|
app.setActivationPolicy('terrible' as any)
|
||||||
|
}).to.throw(/Invalid activation policy: must be one of 'regular', 'accessory', or 'prohibited'/)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('app.requestSingleInstanceLock', () => {
|
describe('app.requestSingleInstanceLock', () => {
|
||||||
it('prevents the second launch of app', function (done) {
|
it('prevents the second launch of app', function (done) {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
|
Loading…
Reference in a new issue