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
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/path_service.h"
|
||||
#include "shell/browser/api/electron_api_app.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 electron
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue