From 6932e17088831dd19e5f678a665fccf24b6d8d74 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 16 Dec 2020 00:34:24 +0100 Subject: [PATCH] chore: remove deprecated systemPreferences methods (#26849) --- docs/breaking-changes.md | 29 +++++++++++++++++++ lib/browser/api/system-preferences.ts | 17 ----------- .../api/electron_api_system_preferences.cc | 11 ------- .../api/electron_api_system_preferences.h | 1 - .../electron_api_system_preferences_mac.mm | 9 ------ spec-main/api-system-preferences-spec.ts | 12 -------- 6 files changed, 29 insertions(+), 50 deletions(-) diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 8935be2e93..791d4d60bb 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -89,6 +89,35 @@ BrowserWindow.getDevToolsExtensions() session.defaultSession.getAllExtensions() ``` +### Removed: methods in `systemPreferences` + +The following `systemPreferences` methods have been deprecated: +* `systemPreferences.isDarkMode()` +* `systemPreferences.isInvertedColorScheme()` +* `systemPreferences.isHighContrastColorScheme()` + +Use the following `nativeTheme` properties instead: +* `nativeTheme.shouldUseDarkColors` +* `nativeTheme.shouldUseInvertedColorScheme` +* `nativeTheme.shouldUseHighContrastColors` + +```js +// Removed in Electron 13 +systemPreferences.isDarkMode() +// Replace with +nativeTheme.shouldUseDarkColors + +// Removed in Electron 13 +systemPreferences.isInvertedColorScheme() +// Replace with +nativeTheme.shouldUseInvertedColorScheme + +// Removed in Electron 13 +systemPreferences.isHighContrastColorScheme() +// Replace with +nativeTheme.shouldUseHighContrastColors +``` + ## Planned Breaking API Changes (12.0) ### Removed: Pepper Flash support diff --git a/lib/browser/api/system-preferences.ts b/lib/browser/api/system-preferences.ts index 7c2b80a320..424c276c63 100644 --- a/lib/browser/api/system-preferences.ts +++ b/lib/browser/api/system-preferences.ts @@ -1,4 +1,3 @@ -import { deprecate } from 'electron/main'; const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences'); if ('getAppLevelAppearance' in systemPreferences) { @@ -17,20 +16,4 @@ if ('getEffectiveAppearance' in systemPreferences) { }); } -systemPreferences.isDarkMode = deprecate.moveAPI( - systemPreferences.isDarkMode, - 'systemPreferences.isDarkMode()', - 'nativeTheme.shouldUseDarkColors' -); -systemPreferences.isInvertedColorScheme = deprecate.moveAPI( - systemPreferences.isInvertedColorScheme, - 'systemPreferences.isInvertedColorScheme()', - 'nativeTheme.shouldUseInvertedColorScheme' -); -systemPreferences.isHighContrastColorScheme = deprecate.moveAPI( - systemPreferences.isHighContrastColorScheme, - 'systemPreferences.isHighContrastColorScheme()', - 'nativeTheme.shouldUseHighContrastColors' -); - export default systemPreferences; diff --git a/shell/browser/api/electron_api_system_preferences.cc b/shell/browser/api/electron_api_system_preferences.cc index c7498dea9e..fdda75bcd7 100644 --- a/shell/browser/api/electron_api_system_preferences.cc +++ b/shell/browser/api/electron_api_system_preferences.cc @@ -31,12 +31,6 @@ SystemPreferences::~SystemPreferences() { #endif } -#if !defined(OS_MAC) -bool SystemPreferences::IsDarkMode() { - return ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors(); -} -#endif - bool SystemPreferences::IsInvertedColorScheme() { return ui::NativeTheme::GetInstanceForNativeUi() ->GetPlatformHighContrastColorScheme() == @@ -115,11 +109,6 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder( &SystemPreferences::IsTrustedAccessibilityClient) .SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess) #endif - .SetMethod("isInvertedColorScheme", - &SystemPreferences::IsInvertedColorScheme) - .SetMethod("isHighContrastColorScheme", - &SystemPreferences::IsHighContrastColorScheme) - .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode) .SetMethod("getAnimationSettings", &SystemPreferences::GetAnimationSettings); } diff --git a/shell/browser/api/electron_api_system_preferences.h b/shell/browser/api/electron_api_system_preferences.h index 8ab140adb9..cd73a51f1d 100644 --- a/shell/browser/api/electron_api_system_preferences.h +++ b/shell/browser/api/electron_api_system_preferences.h @@ -117,7 +117,6 @@ class SystemPreferences v8::Local GetAppLevelAppearance(v8::Isolate* isolate); void SetAppLevelAppearance(gin::Arguments* args); #endif - bool IsDarkMode(); bool IsInvertedColorScheme(); bool IsHighContrastColorScheme(); v8::Local GetAnimationSettings(v8::Isolate* isolate); diff --git a/shell/browser/api/electron_api_system_preferences_mac.mm b/shell/browser/api/electron_api_system_preferences_mac.mm index 43318c456d..96d757f5f9 100644 --- a/shell/browser/api/electron_api_system_preferences_mac.mm +++ b/shell/browser/api/electron_api_system_preferences_mac.mm @@ -628,15 +628,6 @@ void SystemPreferences::RemoveUserDefault(const std::string& name) { [defaults removeObjectForKey:base::SysUTF8ToNSString(name)]; } -bool SystemPreferences::IsDarkMode() { - if (@available(macOS 10.14, *)) { - return ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors(); - } - NSString* mode = [[NSUserDefaults standardUserDefaults] - stringForKey:@"AppleInterfaceStyle"]; - return [mode isEqualToString:@"Dark"]; -} - bool SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled() { return [NSEvent isSwipeTrackingFromScrollEventsEnabled]; } diff --git a/spec-main/api-system-preferences-spec.ts b/spec-main/api-system-preferences-spec.ts index 15429b54de..3670527649 100644 --- a/spec-main/api-system-preferences-spec.ts +++ b/spec-main/api-system-preferences-spec.ts @@ -244,18 +244,6 @@ describe('systemPreferences module', () => { }); }); - describe('systemPreferences.isInvertedColorScheme()', () => { - it('returns a boolean', () => { - expect(systemPreferences.isInvertedColorScheme()).to.be.a('boolean'); - }); - }); - - describe('systemPreferences.isHighContrastColorScheme()', () => { - it('returns a boolean', () => { - expect(systemPreferences.isHighContrastColorScheme()).to.be.a('boolean'); - }); - }); - ifdescribe(process.platform === 'darwin')('systemPreferences.canPromptTouchID()', () => { it('returns a boolean', () => { expect(systemPreferences.canPromptTouchID()).to.be.a('boolean');