From 7685f27b31bd565ecde05307174b1738c0bbd777 Mon Sep 17 00:00:00 2001 From: George Xu <33054982+georgexu99@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:48:02 -0700 Subject: [PATCH] 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 --- docs/api/system-preferences.md | 4 ++++ shell/browser/api/electron_api_system_preferences.cc | 3 +++ shell/browser/api/electron_api_system_preferences.h | 1 + shell/browser/api/electron_api_system_preferences_mac.mm | 5 +++++ spec/ts-smoke/electron/main.ts | 2 -- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index e42e4c1c4d..ab0fafd1ed 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -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`. diff --git a/shell/browser/api/electron_api_system_preferences.cc b/shell/browser/api/electron_api_system_preferences.cc index c735081b40..14594d9790 100644 --- a/shell/browser/api/electron_api_system_preferences.cc +++ b/shell/browser/api/electron_api_system_preferences.cc @@ -95,6 +95,9 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder( .SetMethod("isTrustedAccessibilityClient", &SystemPreferences::IsTrustedAccessibilityClient) .SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess) + .SetProperty( + "accessibilityDisplayShouldReduceTransparency", + &SystemPreferences::AccessibilityDisplayShouldReduceTransparency) #endif .SetMethod("getAnimationSettings", &SystemPreferences::GetAnimationSettings); diff --git a/shell/browser/api/electron_api_system_preferences.h b/shell/browser/api/electron_api_system_preferences.h index 5ea91b4f9e..03db491df6 100644 --- a/shell/browser/api/electron_api_system_preferences.h +++ b/shell/browser/api/electron_api_system_preferences.h @@ -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); diff --git a/shell/browser/api/electron_api_system_preferences_mac.mm b/shell/browser/api/electron_api_system_preferences_mac.mm index a070ac688a..df2868ac99 100644 --- a/shell/browser/api/electron_api_system_preferences_mac.mm +++ b/shell/browser/api/electron_api_system_preferences_mac.mm @@ -598,4 +598,9 @@ v8::Local SystemPreferences::GetEffectiveAppearance( isolate, [NSApplication sharedApplication].effectiveAppearance); } +bool SystemPreferences::AccessibilityDisplayShouldReduceTransparency() { + return [[NSWorkspace sharedWorkspace] + accessibilityDisplayShouldReduceTransparency]; +} + } // namespace electron::api diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index 53699804ce..16c37e96c4 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -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')); }