Skip to content

Commit ebc4370

Browse files
georgexu99VerteDinde
authored andcommitted
feat: expose app accessibility transparency settings api (electron#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]>
1 parent 0f954d3 commit ebc4370

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

docs/api/system-preferences.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ Returns an object with system animation settings.
401401

402402
## Properties
403403

404+
### `systemPreferences.accessibilityDisplayShouldReduceTransparency()` _macOS_
405+
406+
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)
407+
404408
### `systemPreferences.effectiveAppearance` _macOS_ _Readonly_
405409

406410
A `string` property that can be `dark`, `light` or `unknown`.

shell/browser/api/electron_api_system_preferences.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
9595
.SetMethod("isTrustedAccessibilityClient",
9696
&SystemPreferences::IsTrustedAccessibilityClient)
9797
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
98+
.SetProperty(
99+
"accessibilityDisplayShouldReduceTransparency",
100+
&SystemPreferences::AccessibilityDisplayShouldReduceTransparency)
98101
#endif
99102
.SetMethod("getAnimationSettings",
100103
&SystemPreferences::GetAnimationSettings);

shell/browser/api/electron_api_system_preferences.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SystemPreferences
9696
gin::Arguments* args);
9797
void RemoveUserDefault(const std::string& name);
9898
bool IsSwipeTrackingFromScrollEventsEnabled();
99+
bool AccessibilityDisplayShouldReduceTransparency();
99100

100101
std::string GetSystemColor(gin_helper::ErrorThrower thrower,
101102
const std::string& color);

shell/browser/api/electron_api_system_preferences_mac.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,9 @@ AVMediaType ParseMediaType(const std::string& media_type) {
598598
isolate, [NSApplication sharedApplication].effectiveAppearance);
599599
}
600600

601+
bool SystemPreferences::AccessibilityDisplayShouldReduceTransparency() {
602+
return [[NSWorkspace sharedWorkspace]
603+
accessibilityDisplayShouldReduceTransparency];
604+
}
605+
601606
} // namespace electron::api

spec/ts-smoke/electron/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ if (process.platform === 'darwin') {
382382
// @ts-expect-error Removed API
383383
systemPreferences.setAppLevelAppearance('dark');
384384
// @ts-expect-error Removed API
385-
console.log(systemPreferences.appLevelAppearance);
386-
// @ts-expect-error Removed API
387385
console.log(systemPreferences.getColor('alternate-selected-control-text'));
388386
}
389387

0 commit comments

Comments
 (0)