Skip to content

Commit 6a8d187

Browse files
trop[bot]robb
andauthored
feat: add accessibilityDisplayShouldDifferentiateWithoutColor on macOS (#50408)
feat: add nativeTheme.shouldDifferentiateWithoutColor on macOS Adds nativeTheme.shouldDifferentiateWithoutColor on macOS that maps to NSWorkspace.accessibilityDisplayShouldDifferentiateWithoutColor. If true, the user has indicated that they prefer UI that differentiates items with something other than color alone. This is useful for users with color vision deficiency. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Robert Böhnke <robb@robb.is>
1 parent 2962293 commit 6a8d187

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

docs/api/native-theme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ Currently, Windows high contrast is the only system setting that triggers forced
8484
### `nativeTheme.prefersReducedTransparency` _Readonly_
8585

8686
A `boolean` that indicates whether the user has chosen via system accessibility settings to reduce transparency at the OS level.
87+
88+
### `nativeTheme.shouldDifferentiateWithoutColor` _macOS_ _Readonly_
89+
90+
A `boolean` that indicates whether the user prefers UI that differentiates items using something other than color alone (e.g. shapes or labels). This maps to [NSWorkspace.accessibilityDisplayShouldDifferentiateWithoutColor](https://developer.apple.com/documentation/appkit/nsworkspace/accessibilitydisplayshoulddifferentiatewithoutcolor).

shell/browser/api/electron_api_native_theme.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
147147
&NativeTheme::ShouldUseInvertedColorScheme)
148148
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode)
149149
.SetProperty("prefersReducedTransparency",
150-
&NativeTheme::GetPrefersReducedTransparency);
150+
&NativeTheme::GetPrefersReducedTransparency)
151+
#if BUILDFLAG(IS_MAC)
152+
.SetProperty("shouldDifferentiateWithoutColor",
153+
&NativeTheme::ShouldDifferentiateWithoutColor)
154+
#endif
155+
;
151156
}
152157

153158
const char* NativeTheme::GetTypeName() {

shell/browser/api/electron_api_native_theme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class NativeTheme final : public gin_helper::DeprecatedWrappable<NativeTheme>,
5656
bool ShouldUseInvertedColorScheme();
5757
bool InForcedColorsMode();
5858
bool GetPrefersReducedTransparency();
59+
#if BUILDFLAG(IS_MAC)
60+
bool ShouldDifferentiateWithoutColor();
61+
#endif
5962

6063
// ui::NativeThemeObserver:
6164
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;

shell/browser/api/electron_api_native_theme_mac.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@
2626
[[NSApplication sharedApplication] setAppearance:new_appearance];
2727
}
2828

29+
bool NativeTheme::ShouldDifferentiateWithoutColor() {
30+
return [[NSWorkspace sharedWorkspace]
31+
accessibilityDisplayShouldDifferentiateWithoutColor];
32+
}
33+
2934
} // namespace electron::api

spec/api-native-theme-spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { once } from 'node:events';
66
import * as path from 'node:path';
77
import { setTimeout } from 'node:timers/promises';
88

9+
import { ifdescribe } from './lib/spec-helpers';
910
import { closeAllWindows } from './lib/window-helpers';
1011

1112
describe('nativeTheme module', () => {
@@ -119,4 +120,10 @@ describe('nativeTheme module', () => {
119120
expect(nativeTheme.prefersReducedTransparency).to.be.a('boolean');
120121
});
121122
});
123+
124+
ifdescribe(process.platform === 'darwin')('nativeTheme.shouldDifferentiateWithoutColor', () => {
125+
it('returns a boolean', () => {
126+
expect(nativeTheme.shouldDifferentiateWithoutColor).to.be.a('boolean');
127+
});
128+
});
122129
});

0 commit comments

Comments
 (0)