chore: remove deprecated systemPreferences methods (#26849)

This commit is contained in:
Milan Burda 2020-12-16 00:34:24 +01:00 committed by GitHub
parent 6ccebdf712
commit 6932e17088
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 50 deletions

View file

@ -89,6 +89,35 @@ BrowserWindow.getDevToolsExtensions()
session.defaultSession.getAllExtensions() 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) ## Planned Breaking API Changes (12.0)
### Removed: Pepper Flash support ### Removed: Pepper Flash support

View file

@ -1,4 +1,3 @@
import { deprecate } from 'electron/main';
const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences'); const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
if ('getAppLevelAppearance' in systemPreferences) { 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; export default systemPreferences;

View file

@ -31,12 +31,6 @@ SystemPreferences::~SystemPreferences() {
#endif #endif
} }
#if !defined(OS_MAC)
bool SystemPreferences::IsDarkMode() {
return ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors();
}
#endif
bool SystemPreferences::IsInvertedColorScheme() { bool SystemPreferences::IsInvertedColorScheme() {
return ui::NativeTheme::GetInstanceForNativeUi() return ui::NativeTheme::GetInstanceForNativeUi()
->GetPlatformHighContrastColorScheme() == ->GetPlatformHighContrastColorScheme() ==
@ -115,11 +109,6 @@ gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder(
&SystemPreferences::IsTrustedAccessibilityClient) &SystemPreferences::IsTrustedAccessibilityClient)
.SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess) .SetMethod("askForMediaAccess", &SystemPreferences::AskForMediaAccess)
#endif #endif
.SetMethod("isInvertedColorScheme",
&SystemPreferences::IsInvertedColorScheme)
.SetMethod("isHighContrastColorScheme",
&SystemPreferences::IsHighContrastColorScheme)
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode)
.SetMethod("getAnimationSettings", .SetMethod("getAnimationSettings",
&SystemPreferences::GetAnimationSettings); &SystemPreferences::GetAnimationSettings);
} }

View file

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

View file

@ -628,15 +628,6 @@ void SystemPreferences::RemoveUserDefault(const std::string& name) {
[defaults removeObjectForKey:base::SysUTF8ToNSString(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() { bool SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled() {
return [NSEvent isSwipeTrackingFromScrollEventsEnabled]; return [NSEvent isSwipeTrackingFromScrollEventsEnabled];
} }

View file

@ -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()', () => { ifdescribe(process.platform === 'darwin')('systemPreferences.canPromptTouchID()', () => {
it('returns a boolean', () => { it('returns a boolean', () => {
expect(systemPreferences.canPromptTouchID()).to.be.a('boolean'); expect(systemPreferences.canPromptTouchID()).to.be.a('boolean');