From 4c51fa93f5052a769ec5199fe6984d2355811593 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 19 Mar 2019 20:15:40 +0100 Subject: [PATCH] feat: add systemPreferences.getAnimationSettings() (#17382) --- .../browser/api/atom_api_system_preferences.cc | 18 +++++++++++++++++- atom/browser/api/atom_api_system_preferences.h | 1 + docs/api/system-preferences.md | 10 ++++++++++ spec/api-system-preferences-spec.js | 10 ++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_system_preferences.cc b/atom/browser/api/atom_api_system_preferences.cc index b34c7b571b69..1ef7a549fc4c 100644 --- a/atom/browser/api/atom_api_system_preferences.cc +++ b/atom/browser/api/atom_api_system_preferences.cc @@ -8,6 +8,7 @@ #include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/node_includes.h" #include "native_mate/dictionary.h" +#include "ui/gfx/animation/animation.h" #include "ui/gfx/color_utils.h" namespace atom { @@ -43,6 +44,19 @@ bool SystemPreferences::IsHighContrastColorScheme() { } #endif // !defined(OS_WIN) +v8::Local SystemPreferences::GetAnimationSettings( + v8::Isolate* isolate) { + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + dict.SetHidden("simple", true); + dict.Set("shouldRenderRichAnimation", + gfx::Animation::ShouldRenderRichAnimation()); + dict.Set("scrollAnimationsEnabledBySystem", + gfx::Animation::ScrollAnimationsEnabledBySystem()); + dict.Set("prefersReducedMotion", gfx::Animation::PrefersReducedMotion()); + + return dict.GetHandle(); +} + // static mate::Handle SystemPreferences::Create( v8::Isolate* isolate) { @@ -105,7 +119,9 @@ void SystemPreferences::BuildPrototype( &SystemPreferences::IsInvertedColorScheme) .SetMethod("isHighContrastColorScheme", &SystemPreferences::IsHighContrastColorScheme) - .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode); + .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode) + .SetMethod("getAnimationSettings", + &SystemPreferences::GetAnimationSettings); } } // namespace api diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 2a71ed952cc3..becd6bbea0af 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -117,6 +117,7 @@ class SystemPreferences : public mate::EventEmitter bool IsDarkMode(); bool IsInvertedColorScheme(); bool IsHighContrastColorScheme(); + v8::Local GetAnimationSettings(v8::Isolate* isolate); protected: explicit SystemPreferences(v8::Isolate* isolate); diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 29ff9eea6d33..f3ca49cbd7f0 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -429,3 +429,13 @@ Returns `Promise` - A promise that resolves with `true` if consent was **Important:** In order to properly leverage this API, you [must set](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos?language=objc) the `NSMicrophoneUsageDescription` and `NSCameraUsageDescription` strings in your app's `Info.plist` file. The values for these keys will be used to populate the permission dialogs so that the user will be properly informed as to the purpose of the permission request. See [Electron Application Distribution](https://electronjs.org/docs/tutorial/application-distribution#macos) for more information about how to set these in the context of Electron. This user consent was not required until macOS 10.14 Mojave, so this method will always return `true` if your system is running 10.13 High Sierra or lower. + +### `systemPreferences.getAnimationSettings()` + +Returns `Object`: + +* `shouldRenderRichAnimation` Boolean - Returns true if rich animations should be rendered. Looks at session type (e.g. remote desktop) and accessibility settings to give guidance for heavy animations. +* `scrollAnimationsEnabledBySystem` Boolean - Determines on a per-platform basis whether scroll animations (e.g. produced by home/end key) should be enabled. +* `prefersReducedMotion` Boolean - Determines whether the user desires reduced motion based on platform APIs. + +Returns an object with system animation settings. diff --git a/spec/api-system-preferences-spec.js b/spec/api-system-preferences-spec.js index 653ae90b2ea6..cddcf38cbe43 100644 --- a/spec/api-system-preferences-spec.js +++ b/spec/api-system-preferences-spec.js @@ -173,4 +173,14 @@ describe('systemPreferences module', () => { assert.strictEqual(typeof systemPreferences.isInvertedColorScheme(), 'boolean') }) }) + + describe('systemPreferences.getAnimationSettings()', () => { + it('returns an object with all properties', () => { + const settings = systemPreferences.getAnimationSettings() + assert.strictEqual(typeof settings, 'object') + assert.strictEqual(typeof settings.shouldRenderRichAnimation, 'boolean') + assert.strictEqual(typeof settings.scrollAnimationsEnabledBySystem, 'boolean') + assert.strictEqual(typeof settings.prefersReducedMotion, 'boolean') + }) + }) })