Skip to content

Commit

Permalink
chore: remove deprecated systemPreferences color scheme events
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored and codebytere committed Aug 10, 2023
1 parent 1ce2fdd commit 6cd5202
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 49 deletions.
18 changes: 0 additions & 18 deletions docs/api/system-preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
18 changes: 18 additions & 0 deletions docs/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (25.0)

### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol`
Expand Down
10 changes: 0 additions & 10 deletions shell/browser/api/electron_api_system_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Value> SystemPreferences::GetAnimationSettings(
v8::Isolate* isolate) {
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
Expand Down
6 changes: 0 additions & 6 deletions shell/browser/api/electron_api_system_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ class SystemPreferences
v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
void SetAppLevelAppearance(gin::Arguments* args);
#endif
bool IsInvertedColorScheme();
bool IsHighContrastColorScheme();
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);

// disable copy
Expand Down Expand Up @@ -158,10 +156,6 @@ class SystemPreferences

std::string current_color_;

bool inverted_color_scheme_ = false;

bool high_contrast_color_scheme_ = false;

std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
#endif
};
Expand Down
15 changes: 0 additions & 15 deletions shell/browser/api/electron_api_system_preferences_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

Expand Down
3 changes: 3 additions & 0 deletions spec/ts-smoke/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down

0 comments on commit 6cd5202

Please sign in to comment.