feat: add systemPreferences.getAnimationSettings() (#17382)

This commit is contained in:
Milan Burda 2019-03-19 20:15:40 +01:00 committed by Samuel Attard
parent 4d8e024b6d
commit 4c51fa93f5
4 changed files with 38 additions and 1 deletions

View file

@ -8,6 +8,7 @@
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
namespace atom { namespace atom {
@ -43,6 +44,19 @@ bool SystemPreferences::IsHighContrastColorScheme() {
} }
#endif // !defined(OS_WIN) #endif // !defined(OS_WIN)
v8::Local<v8::Value> 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 // static
mate::Handle<SystemPreferences> SystemPreferences::Create( mate::Handle<SystemPreferences> SystemPreferences::Create(
v8::Isolate* isolate) { v8::Isolate* isolate) {
@ -105,7 +119,9 @@ void SystemPreferences::BuildPrototype(
&SystemPreferences::IsInvertedColorScheme) &SystemPreferences::IsInvertedColorScheme)
.SetMethod("isHighContrastColorScheme", .SetMethod("isHighContrastColorScheme",
&SystemPreferences::IsHighContrastColorScheme) &SystemPreferences::IsHighContrastColorScheme)
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode); .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode)
.SetMethod("getAnimationSettings",
&SystemPreferences::GetAnimationSettings);
} }
} // namespace api } // namespace api

View file

@ -117,6 +117,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
bool IsDarkMode(); bool IsDarkMode();
bool IsInvertedColorScheme(); bool IsInvertedColorScheme();
bool IsHighContrastColorScheme(); bool IsHighContrastColorScheme();
v8::Local<v8::Value> GetAnimationSettings(v8::Isolate* isolate);
protected: protected:
explicit SystemPreferences(v8::Isolate* isolate); explicit SystemPreferences(v8::Isolate* isolate);

View file

@ -429,3 +429,13 @@ Returns `Promise<Boolean>` - 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. **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. 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.

View file

@ -173,4 +173,14 @@ describe('systemPreferences module', () => {
assert.strictEqual(typeof systemPreferences.isInvertedColorScheme(), 'boolean') 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')
})
})
}) })