Browse Source

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

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 <[email protected]>
George Xu 1 year ago
parent
commit
3f142ad039

+ 4 - 0
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`.

+ 3 - 0
shell/browser/api/electron_api_system_preferences.cc

@@ -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);

+ 1 - 0
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);

+ 5 - 0
shell/browser/api/electron_api_system_preferences_mac.mm

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

+ 0 - 2
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'));
 }