Browse Source

chore: remove deprecated systemPreferences methods (#26849)

Milan Burda 4 years ago
parent
commit
6932e17088

+ 29 - 0
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

+ 0 - 17
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;

+ 0 - 11
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);
 }

+ 0 - 1
shell/browser/api/electron_api_system_preferences.h

@@ -117,7 +117,6 @@ class SystemPreferences
   v8::Local<v8::Value> GetAppLevelAppearance(v8::Isolate* isolate);
   void SetAppLevelAppearance(gin::Arguments* args);
 #endif
-  bool IsDarkMode();
   bool IsInvertedColorScheme();
   bool IsHighContrastColorScheme();
   v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);

+ 0 - 9
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];
 }

+ 0 - 12
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');