refactor: ginify SystemPreferences (#24675)

This commit is contained in:
Jeremy Rose 2020-07-28 11:03:30 -07:00 committed by GitHub
parent 3f45fc24bb
commit 362da77c0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 70 deletions

View file

@ -1,15 +1,10 @@
import { EventEmitter } from 'events';
import { deprecate } from 'electron/main';
const { systemPreferences, SystemPreferences } = process._linkedBinding('electron_browser_system_preferences');
// SystemPreferences is an EventEmitter.
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype);
EventEmitter.call(systemPreferences);
const { systemPreferences } = process._linkedBinding('electron_browser_system_preferences');
if ('getAppLevelAppearance' in systemPreferences) {
const nativeALAGetter = systemPreferences.getAppLevelAppearance;
const nativeALASetter = systemPreferences.setAppLevelAppearance;
Object.defineProperty(SystemPreferences.prototype, 'appLevelAppearance', {
Object.defineProperty(systemPreferences, 'appLevelAppearance', {
get: () => nativeALAGetter.call(systemPreferences),
set: (appearance) => nativeALASetter.call(systemPreferences, appearance)
});
@ -17,25 +12,25 @@ if ('getAppLevelAppearance' in systemPreferences) {
if ('getEffectiveAppearance' in systemPreferences) {
const nativeEAGetter = systemPreferences.getAppLevelAppearance;
Object.defineProperty(SystemPreferences.prototype, 'effectiveAppearance', {
Object.defineProperty(systemPreferences, 'effectiveAppearance', {
get: () => nativeEAGetter.call(systemPreferences)
});
}
SystemPreferences.prototype.isDarkMode = deprecate.moveAPI(
SystemPreferences.prototype.isDarkMode,
systemPreferences.isDarkMode = deprecate.moveAPI(
systemPreferences.isDarkMode,
'systemPreferences.isDarkMode()',
'nativeTheme.shouldUseDarkColors'
);
SystemPreferences.prototype.isInvertedColorScheme = deprecate.moveAPI(
SystemPreferences.prototype.isInvertedColorScheme,
systemPreferences.isInvertedColorScheme = deprecate.moveAPI(
systemPreferences.isInvertedColorScheme,
'systemPreferences.isInvertedColorScheme()',
'nativeTheme.shouldUseInvertedColorScheme'
);
SystemPreferences.prototype.isHighContrastColorScheme = deprecate.moveAPI(
SystemPreferences.prototype.isHighContrastColorScheme,
systemPreferences.isHighContrastColorScheme = deprecate.moveAPI(
systemPreferences.isHighContrastColorScheme,
'systemPreferences.isHighContrastColorScheme()',
'nativeTheme.shouldUseHighContrastColors'
);
module.exports = systemPreferences;
export default systemPreferences;