From d1661828651e477eed5bf4a1e3b933b04614fece Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 14 Aug 2023 01:37:18 -0700 Subject: [PATCH] chore: remove deprecated systemPreferences color scheme events (#39341) --- docs/api/system-preferences.md | 18 ------------------ docs/breaking-changes.md | 18 ++++++++++++++++++ .../api/electron_api_system_preferences.cc | 10 ---------- .../api/electron_api_system_preferences.h | 6 ------ .../api/electron_api_system_preferences_win.cc | 15 --------------- spec/ts-smoke/electron/main.ts | 3 +++ 6 files changed, 21 insertions(+), 49 deletions(-) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index e66e5d0d4e9b..1110ff94f4b2 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -27,24 +27,6 @@ Returns: * `event` Event -### Event: 'inverted-color-scheme-changed' _Windows_ _Deprecated_ - -Returns: - -* `event` Event -* `invertedColorScheme` boolean - `true` if an inverted color scheme (a high contrast color scheme with light text and dark backgrounds) is being used, `false` otherwise. - -**Deprecated:** Should use the new [`updated`](native-theme.md#event-updated) event on the `nativeTheme` module. - -### Event: 'high-contrast-color-scheme-changed' _Windows_ _Deprecated_ - -Returns: - -* `event` Event -* `highContrastColorScheme` boolean - `true` if a high contrast theme is being used, `false` otherwise. - -**Deprecated:** Should use the new [`updated`](native-theme.md#event-updated) event on the `nativeTheme` module. - ## Methods ### `systemPreferences.isSwipeTrackingFromScrollEventsEnabled()` _macOS_ diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index a0cbfc2e76c4..25833fb39fa5 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -27,6 +27,24 @@ The `ipcRenderer.sendTo()` API has been deprecated. It should be replaced by set The `senderId` and `senderIsMainFrame` properties of `IpcRendererEvent` have been deprecated as well. +### Removed: color scheme events in `systemPreferences` + +The following `systemPreferences` events have been removed: + +* `inverted-color-scheme-changed` +* `high-contrast-color-scheme-changed` + +Use the new `updated` event on the `nativeTheme` module instead. + +```js +// Removed +systemPreferences.on('inverted-color-scheme-changed', () => { /* ... */ }) +systemPreferences.on('high-contrast-color-scheme-changed', () => { /* ... */ }) + +// Replace with +nativeTheme.on('updated', () => { /* ... */ }) +``` + ## Planned Breaking API Changes (26.0) ### Deprecated: `webContents.getPrinters` diff --git a/shell/browser/api/electron_api_system_preferences.cc b/shell/browser/api/electron_api_system_preferences.cc index f78d72d00d21..e199cf30e894 100644 --- a/shell/browser/api/electron_api_system_preferences.cc +++ b/shell/browser/api/electron_api_system_preferences.cc @@ -33,16 +33,6 @@ SystemPreferences::~SystemPreferences() { SystemPreferences::~SystemPreferences() = default; #endif -bool SystemPreferences::IsInvertedColorScheme() { - return ui::NativeTheme::GetInstanceForNativeUi() - ->GetPlatformHighContrastColorScheme() == - ui::NativeTheme::PlatformHighContrastColorScheme::kDark; -} - -bool SystemPreferences::IsHighContrastColorScheme() { - return ui::NativeTheme::GetInstanceForNativeUi()->UserHasContrastPreference(); -} - v8::Local SystemPreferences::GetAnimationSettings( v8::Isolate* isolate) { gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); diff --git a/shell/browser/api/electron_api_system_preferences.h b/shell/browser/api/electron_api_system_preferences.h index b311e97fc683..cd4fce5cc77b 100644 --- a/shell/browser/api/electron_api_system_preferences.h +++ b/shell/browser/api/electron_api_system_preferences.h @@ -115,8 +115,6 @@ class SystemPreferences v8::Local GetAppLevelAppearance(v8::Isolate* isolate); void SetAppLevelAppearance(gin::Arguments* args); #endif - bool IsInvertedColorScheme(); - bool IsHighContrastColorScheme(); v8::Local GetAnimationSettings(v8::Isolate* isolate); // disable copy @@ -158,10 +156,6 @@ class SystemPreferences std::string current_color_; - bool inverted_color_scheme_ = false; - - bool high_contrast_color_scheme_ = false; - std::unique_ptr color_change_listener_; #endif }; diff --git a/shell/browser/api/electron_api_system_preferences_win.cc b/shell/browser/api/electron_api_system_preferences_win.cc index a63c7fef2840..982edd2131c6 100644 --- a/shell/browser/api/electron_api_system_preferences_win.cc +++ b/shell/browser/api/electron_api_system_preferences_win.cc @@ -158,9 +158,6 @@ std::string SystemPreferences::GetMediaAccessStatus( } void SystemPreferences::InitializeWindow() { - inverted_color_scheme_ = IsInvertedColorScheme(); - high_contrast_color_scheme_ = IsHighContrastColorScheme(); - // Wait until app is ready before creating sys color listener // Creating this listener before the app is ready causes global shortcuts // to not fire @@ -216,18 +213,6 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd, } void SystemPreferences::OnSysColorChange() { - bool new_inverted_color_scheme = IsInvertedColorScheme(); - if (new_inverted_color_scheme != inverted_color_scheme_) { - inverted_color_scheme_ = new_inverted_color_scheme; - Emit("inverted-color-scheme-changed", new_inverted_color_scheme); - } - - bool new_high_contrast_color_scheme = IsHighContrastColorScheme(); - if (new_high_contrast_color_scheme != high_contrast_color_scheme_) { - high_contrast_color_scheme_ = new_high_contrast_color_scheme; - Emit("high-contrast-color-scheme-changed", new_high_contrast_color_scheme); - } - Emit("color-changed"); } diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index a81377cbe165..f83f4ea470cf 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -365,7 +365,10 @@ if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) { if (process.platform === 'win32') { systemPreferences.on('color-changed', () => { console.log('color changed'); }); + // @ts-expect-error Removed API systemPreferences.on('inverted-color-scheme-changed', (_, inverted) => console.log(inverted ? 'inverted' : 'not inverted')); + // @ts-expect-error Removed API + systemPreferences.on('high-contrast-color-scheme-changed', (_, highContrast) => console.log(highContrast ? 'high contrast' : 'not high contrast')); console.log('Color for menu is', systemPreferences.getColor('menu')); }