feat: expose app accessibility transparency settings api (#39631)

* 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>
This commit is contained in:
George Xu 2023-09-20 12:48:02 -07:00 committed by GitHub
parent 463586a6c5
commit 7685f27b31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 2 deletions

View file

@ -401,6 +401,10 @@ Returns an object with system animation settings.
## Properties ## 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_ ### `systemPreferences.effectiveAppearance` _macOS_ _Readonly_
A `string` property that can be `dark`, `light` or `unknown`. A `string` property that can be `dark`, `light` or `unknown`.

View file

@ -95,6 +95,9 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
.SetMethod("isTrustedAccessibilityClient", .SetMethod("isTrustedAccessibilityClient",
&SystemPreferences::IsTrustedAccessibilityClient) &SystemPreferences::IsTrustedAccessibilityClient)
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess) .SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
.SetProperty(
"accessibilityDisplayShouldReduceTransparency",
&SystemPreferences::AccessibilityDisplayShouldReduceTransparency)
#endif #endif
.SetMethod("getAnimationSettings", .SetMethod("getAnimationSettings",
&SystemPreferences::GetAnimationSettings); &SystemPreferences::GetAnimationSettings);

View file

@ -96,6 +96,7 @@ class SystemPreferences
gin::Arguments* args); gin::Arguments* args);
void RemoveUserDefault(const std::string& name); void RemoveUserDefault(const std::string& name);
bool IsSwipeTrackingFromScrollEventsEnabled(); bool IsSwipeTrackingFromScrollEventsEnabled();
bool AccessibilityDisplayShouldReduceTransparency();
std::string GetSystemColor(gin_helper::ErrorThrower thrower, std::string GetSystemColor(gin_helper::ErrorThrower thrower,
const std::string& color); const std::string& color);

View file

@ -598,4 +598,9 @@ v8::Local<v8::Value> SystemPreferences::GetEffectiveAppearance(
isolate, [NSApplication sharedApplication].effectiveAppearance); isolate, [NSApplication sharedApplication].effectiveAppearance);
} }
bool SystemPreferences::AccessibilityDisplayShouldReduceTransparency() {
return [[NSWorkspace sharedWorkspace]
accessibilityDisplayShouldReduceTransparency];
}
} // namespace electron::api } // namespace electron::api

View file

@ -382,8 +382,6 @@ if (process.platform === 'darwin') {
// @ts-expect-error Removed API // @ts-expect-error Removed API
systemPreferences.setAppLevelAppearance('dark'); systemPreferences.setAppLevelAppearance('dark');
// @ts-expect-error Removed API // @ts-expect-error Removed API
console.log(systemPreferences.appLevelAppearance);
// @ts-expect-error Removed API
console.log(systemPreferences.getColor('alternate-selected-control-text')); console.log(systemPreferences.getColor('alternate-selected-control-text'));
} }