Skip to content

Commit

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

* docs: fix typo

* chore: add doc

* change to property

* add as property instead of method

* chore: fix lint

* rename function name in header

---------

Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
  • Loading branch information
georgexu99 and VerteDinde committed Oct 2, 2023
1 parent 10db238 commit 67ba35f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/api/system-preferences.md
Expand Up @@ -401,6 +401,10 @@ Returns an object with system animation settings.

## Properties

### `systemPreferences.accessibilityDisplayShouldReduceTransparency()` _macOS_

A `boolean` property which determines whether the app avoids using semitransparent backgrounds. This maps to [NSWorkspace.accessibilityDisplayShouldReduceTransparency](https://developer.apple.com/documentation/appkit/nsworkspace/1533006-accessibilitydisplayshouldreduce)

### `systemPreferences.effectiveAppearance` _macOS_ _Readonly_

A `string` property that can be `dark`, `light` or `unknown`.
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/api/electron_api_system_preferences.cc
Expand Up @@ -96,6 +96,9 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
.SetMethod("isTrustedAccessibilityClient",
&SystemPreferences::IsTrustedAccessibilityClient)
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
.SetProperty(
"accessibilityDisplayShouldReduceTransparency",
&SystemPreferences::AccessibilityDisplayShouldReduceTransparency)
#endif
.SetMethod("getAnimationSettings",
&SystemPreferences::GetAnimationSettings);
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_system_preferences.h
Expand Up @@ -96,6 +96,7 @@ class SystemPreferences
gin::Arguments* args);
void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled();
bool AccessibilityDisplayShouldReduceTransparency();

std::string GetSystemColor(gin_helper::ErrorThrower thrower,
const std::string& color);
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/api/electron_api_system_preferences_mac.mm
Expand Up @@ -602,4 +602,9 @@ AVMediaType ParseMediaType(const std::string& media_type) {
isolate, [NSApplication sharedApplication].effectiveAppearance);
}

bool SystemPreferences::AccessibilityDisplayShouldReduceTransparency() {
return [[NSWorkspace sharedWorkspace]
accessibilityDisplayShouldReduceTransparency];
}

} // namespace electron::api
2 changes: 0 additions & 2 deletions spec/ts-smoke/electron/main.ts
Expand Up @@ -382,8 +382,6 @@ if (process.platform === 'darwin') {
// @ts-expect-error Removed API
systemPreferences.setAppLevelAppearance('dark');
// @ts-expect-error Removed API
console.log(systemPreferences.appLevelAppearance);
// @ts-expect-error Removed API
console.log(systemPreferences.getColor('alternate-selected-control-text'));
}

Expand Down

0 comments on commit 67ba35f

Please sign in to comment.