diff --git a/docs/api/native-theme.md b/docs/api/native-theme.md index 3235eba9a78d..e6bdd6c80606 100644 --- a/docs/api/native-theme.md +++ b/docs/api/native-theme.md @@ -72,3 +72,7 @@ or is being instructed to use an inverted color scheme. A `boolean` indicating whether Chromium is in forced colors mode, controlled by system accessibility settings. Currently, Windows high contrast is the only system setting that triggers forced colors mode. + +### `nativeTheme.prefersReducedTransparency` _Readonly_ + +A `boolean` that indicates the whether the user has chosen via system accessibility settings to reduce transparency at the OS level. diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 1c4512bc6a7f..ad6f72007aa5 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -401,10 +401,12 @@ Returns an object with system animation settings. ## Properties -### `systemPreferences.accessibilityDisplayShouldReduceTransparency()` _macOS_ +### `systemPreferences.accessibilityDisplayShouldReduceTransparency` _macOS_ _Deprecated_ 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) +**Deprecated:** Use the new [`nativeTheme.prefersReducedTransparency`](native-theme.md#nativethemeprefersreducedtransparency-readonly) API. + ### `systemPreferences.effectiveAppearance` _macOS_ _Readonly_ A `string` property that can be `dark`, `light` or `unknown`. diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 7099131f69ed..1f5774ca12fc 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -12,6 +12,20 @@ This document uses the following convention to categorize breaking changes: * **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release. * **Removed:** An API or feature was removed, and is no longer supported by Electron. +## Planned Breaking API Changes (33.0) + +### Deprecated: `systemPreferences.accessibilityDisplayShouldReduceTransparency` + +The `systemPreferences.accessibilityDisplayShouldReduceTransparency` property is now deprecated in favor of the new `nativeTheme.prefersReducedTransparency`, which provides identical information and works cross-platform. + +```js +// Deprecated +const shouldReduceTransparency = systemPreferences.accessibilityDisplayShouldReduceTransparency + +// Replace with: +const prefersReducedTransparency = nativeTheme.prefersReducedTransparency +``` + ## Planned Breaking API Changes (32.0) ### Removed: `File.path` diff --git a/filenames.auto.gni b/filenames.auto.gni index a9a4f6d7c09c..574797c555cc 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -354,6 +354,7 @@ auto_filenames = { "lib/browser/message-port-main.ts", "lib/common/api/net-client-request.ts", "lib/common/define-properties.ts", + "lib/common/deprecate.ts", "lib/common/init.ts", "lib/common/webpack-globals-provider.ts", "lib/utility/api/exports/electron.ts", diff --git a/lib/browser/api/system-preferences.ts b/lib/browser/api/system-preferences.ts index 3c17fbc5ad86..33c1a4eb7dbe 100644 --- a/lib/browser/api/system-preferences.ts +++ b/lib/browser/api/system-preferences.ts @@ -1,3 +1,4 @@ +import * as deprecate from '@electron/internal/common/deprecate'; const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences'); if ('getEffectiveAppearance' in systemPreferences) { @@ -7,4 +8,15 @@ if ('getEffectiveAppearance' in systemPreferences) { }); } +if ('accessibilityDisplayShouldReduceTransparency' in systemPreferences) { + const reduceTransparencyDeprecated = deprecate.warnOnce('systemPreferences.accessibilityDisplayShouldReduceTransparency', 'nativeTheme.prefersReducedTransparency'); + const nativeReduceTransparency = systemPreferences.accessibilityDisplayShouldReduceTransparency; + Object.defineProperty(systemPreferences, 'accessibilityDisplayShouldReduceTransparency', { + get: () => { + reduceTransparencyDeprecated(); + return nativeReduceTransparency; + } + }); +} + export default systemPreferences; diff --git a/shell/browser/api/electron_api_native_theme.cc b/shell/browser/api/electron_api_native_theme.cc index 3235f51ac927..a86481e4d67a 100644 --- a/shell/browser/api/electron_api_native_theme.cc +++ b/shell/browser/api/electron_api_native_theme.cc @@ -67,6 +67,10 @@ bool NativeTheme::InForcedColorsMode() { return ui_theme_->InForcedColorsMode(); } +bool NativeTheme::GetPrefersReducedTransparency() { + return ui_theme_->GetPrefersReducedTransparency(); +} + #if BUILDFLAG(IS_MAC) const CFStringRef WhiteOnBlack = CFSTR("whiteOnBlack"); const CFStringRef UniversalAccessDomain = CFSTR("com.apple.universalaccess"); @@ -107,7 +111,9 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder( &NativeTheme::ShouldUseHighContrastColors) .SetProperty("shouldUseInvertedColorScheme", &NativeTheme::ShouldUseInvertedColorScheme) - .SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode); + .SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode) + .SetProperty("prefersReducedTransparency", + &NativeTheme::GetPrefersReducedTransparency); } 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 a1f7798014b6..51db378549d1 100644 --- a/shell/browser/api/electron_api_native_theme.h +++ b/shell/browser/api/electron_api_native_theme.h @@ -46,6 +46,7 @@ class NativeTheme : public gin::Wrappable, bool ShouldUseHighContrastColors(); bool ShouldUseInvertedColorScheme(); bool InForcedColorsMode(); + bool GetPrefersReducedTransparency(); // ui::NativeThemeObserver: void OnNativeThemeUpdated(ui::NativeTheme* theme) override; diff --git a/spec/api-native-theme-spec.ts b/spec/api-native-theme-spec.ts index 70bf2f0a02a1..a6abb6762cc9 100644 --- a/spec/api-native-theme-spec.ts +++ b/spec/api-native-theme-spec.ts @@ -105,4 +105,10 @@ describe('nativeTheme module', () => { expect(nativeTheme.inForcedColorsMode).to.be.a('boolean'); }); }); + + describe('nativeTheme.prefersReducesTransparency', () => { + it('returns a boolean', () => { + expect(nativeTheme.prefersReducedTransparency).to.be.a('boolean'); + }); + }); });