Skip to content

Commit

Permalink
feat: expose app accessibility status api (#16119)
Browse files Browse the repository at this point in the history
* feat: expose app accessibility status api

* fix prompt
  • Loading branch information
codebytere authored and John Kleinschmidt committed Dec 18, 2018
1 parent dc93d94 commit a58d989
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_system_preferences.cc
Expand Up @@ -89,6 +89,8 @@ void SystemPreferences::BuildPrototype(
&SystemPreferences::GetAppLevelAppearance)
.SetMethod("setAppLevelAppearance",
&SystemPreferences::SetAppLevelAppearance)
.SetMethod("isTrustedAccessibilityClient",
&SystemPreferences::IsTrustedAccessibilityClient)
.SetMethod("getMediaAccessStatus",
&SystemPreferences::GetMediaAccessStatus)
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_system_preferences.h
Expand Up @@ -92,6 +92,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled();

bool IsTrustedAccessibilityClient(bool prompt);

// TODO(codebytere): Write tests for these methods once we
// are running tests on a Mojave machine
std::string GetMediaAccessStatus(const std::string& media_type,
Expand Down
5 changes: 5 additions & 0 deletions atom/browser/api/atom_api_system_preferences_mac.mm
Expand Up @@ -378,6 +378,11 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}
}

bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
NSDictionary* options = @{(id)kAXTrustedCheckOptionPrompt : @(prompt)};
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
}

std::string SystemPreferences::GetMediaAccessStatus(
const std::string& media_type,
mate::Arguments* args) {
Expand Down
6 changes: 6 additions & 0 deletions docs/api/system-preferences.md
Expand Up @@ -327,6 +327,12 @@ You can use the `setAppLevelAppearance` API to set this value.
Sets the appearance setting for your application, this should override the
system default and override the value of `getEffectiveAppearance`.

### `systemPreferences.isTrustedAccessibilityClient(prompt)` _macOS_

* `prompt` Boolean - whether or not the user will be informed via prompt if the current process is untrusted.

Returns `Boolean` - `true` if the current process is a trusted accessibility client and `false` if it is not.

### `systemPreferences.getMediaAccessStatus(mediaType)` _macOS_

* `mediaType` String - `microphone` or `camera`.
Expand Down

0 comments on commit a58d989

Please sign in to comment.