From dee8f5a0ffa69116117fb00c4faaaacd30218e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robb=20B=C3=B6hnke?= <212465+robb@users.noreply.github.com> Date: Sat, 21 Mar 2026 00:51:23 +0100 Subject: [PATCH] feat: add accessibilityDisplayShouldDifferentiateWithoutColor on macOS (#49912) 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. --- docs/api/native-theme.md | 4 ++++ shell/browser/api/electron_api_native_theme.cc | 7 ++++++- shell/browser/api/electron_api_native_theme.h | 3 +++ shell/browser/api/electron_api_native_theme_mac.mm | 5 +++++ spec/api-native-theme-spec.ts | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/api/native-theme.md b/docs/api/native-theme.md index abd9718793..c587cb8ca2 100644 --- a/docs/api/native-theme.md +++ b/docs/api/native-theme.md @@ -84,3 +84,7 @@ Currently, Windows high contrast is the only system setting that triggers forced ### `nativeTheme.prefersReducedTransparency` _Readonly_ A `boolean` that indicates whether the user has chosen via system accessibility settings to reduce transparency at the OS level. + +### `nativeTheme.shouldDifferentiateWithoutColor` _macOS_ _Readonly_ + +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). diff --git a/shell/browser/api/electron_api_native_theme.cc b/shell/browser/api/electron_api_native_theme.cc index fa7f9fbbef..df06464983 100644 --- a/shell/browser/api/electron_api_native_theme.cc +++ b/shell/browser/api/electron_api_native_theme.cc @@ -147,7 +147,12 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder( &NativeTheme::ShouldUseInvertedColorScheme) .SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode) .SetProperty("prefersReducedTransparency", - &NativeTheme::GetPrefersReducedTransparency); + &NativeTheme::GetPrefersReducedTransparency) +#if BUILDFLAG(IS_MAC) + .SetProperty("shouldDifferentiateWithoutColor", + &NativeTheme::ShouldDifferentiateWithoutColor) +#endif + ; } const char* NativeTheme::GetTypeName() { diff --git a/shell/browser/api/electron_api_native_theme.h b/shell/browser/api/electron_api_native_theme.h index 7a4b7b4eec..8dd630f132 100644 --- a/shell/browser/api/electron_api_native_theme.h +++ b/shell/browser/api/electron_api_native_theme.h @@ -56,6 +56,9 @@ class NativeTheme final : public gin_helper::DeprecatedWrappable, bool ShouldUseInvertedColorScheme(); bool InForcedColorsMode(); bool GetPrefersReducedTransparency(); +#if BUILDFLAG(IS_MAC) + bool ShouldDifferentiateWithoutColor(); +#endif // ui::NativeThemeObserver: void OnNativeThemeUpdated(ui::NativeTheme* theme) override; diff --git a/shell/browser/api/electron_api_native_theme_mac.mm b/shell/browser/api/electron_api_native_theme_mac.mm index ec409e5df5..045354a399 100644 --- a/shell/browser/api/electron_api_native_theme_mac.mm +++ b/shell/browser/api/electron_api_native_theme_mac.mm @@ -26,4 +26,9 @@ void NativeTheme::UpdateMacOSAppearanceForOverrideValue( [[NSApplication sharedApplication] setAppearance:new_appearance]; } +bool NativeTheme::ShouldDifferentiateWithoutColor() { + return [[NSWorkspace sharedWorkspace] + accessibilityDisplayShouldDifferentiateWithoutColor]; +} + } // namespace electron::api diff --git a/spec/api-native-theme-spec.ts b/spec/api-native-theme-spec.ts index d68caf06fb..c02308a5e5 100644 --- a/spec/api-native-theme-spec.ts +++ b/spec/api-native-theme-spec.ts @@ -6,6 +6,7 @@ import { once } from 'node:events'; import * as path from 'node:path'; import { setTimeout } from 'node:timers/promises'; +import { ifdescribe } from './lib/spec-helpers'; import { closeAllWindows } from './lib/window-helpers'; describe('nativeTheme module', () => { @@ -119,4 +120,10 @@ describe('nativeTheme module', () => { expect(nativeTheme.prefersReducedTransparency).to.be.a('boolean'); }); }); + + ifdescribe(process.platform === 'darwin')('nativeTheme.shouldDifferentiateWithoutColor', () => { + it('returns a boolean', () => { + expect(nativeTheme.shouldDifferentiateWithoutColor).to.be.a('boolean'); + }); + }); });