Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
flutter::SettingsPlugin Class Reference

#include <settings_plugin.h>

Public Types

enum struct  PlatformBrightness { kDark , kLight }
 

Public Member Functions

 SettingsPlugin (BinaryMessenger *messenger, TaskRunner *task_runner)
 
virtual ~SettingsPlugin ()
 
void SendSettings ()
 
virtual void StartWatching ()
 
virtual void StopWatching ()
 
virtual void UpdateHighContrastMode (bool is_high_contrast)
 

Protected Member Functions

virtual bool GetAlwaysUse24HourFormat ()
 
virtual float GetTextScaleFactor ()
 
virtual PlatformBrightness GetPreferredBrightness ()
 
virtual void WatchPreferredBrightnessChanged ()
 
virtual void WatchTextScaleFactorChanged ()
 

Protected Attributes

bool is_high_contrast_ = false
 

Detailed Description

Definition at line 25 of file settings_plugin.h.

Member Enumeration Documentation

◆ PlatformBrightness

Enumerator
kDark 
kLight 

Definition at line 27 of file settings_plugin.h.

27{ kDark, kLight };

Constructor & Destructor Documentation

◆ SettingsPlugin()

flutter::SettingsPlugin::SettingsPlugin ( BinaryMessenger messenger,
TaskRunner task_runner 
)
explicit

Definition at line 57 of file settings_plugin.cc.

59 : channel_(std::make_unique<BasicMessageChannel<rapidjson::Document>>(
60 messenger,
63 task_runner_(task_runner) {}
static NSString *const kChannelName
static const JsonMessageCodec & GetInstance()

◆ ~SettingsPlugin()

flutter::SettingsPlugin::~SettingsPlugin ( )
virtual

Definition at line 65 of file settings_plugin.cc.

65 {
67}

Member Function Documentation

◆ GetAlwaysUse24HourFormat()

bool flutter::SettingsPlugin::GetAlwaysUse24HourFormat ( )
protectedvirtual

Definition at line 112 of file settings_plugin.cc.

112 {
114}
std::wstring GetUserTimeFormat()
bool Prefer24HourTime(std::wstring time_format)

◆ GetPreferredBrightness()

SettingsPlugin::PlatformBrightness flutter::SettingsPlugin::GetPreferredBrightness ( )
protectedvirtual

Definition at line 131 of file settings_plugin.cc.

131 {
132 if (is_high_contrast_) {
133 DWORD window_color = GetSysColor(COLOR_WINDOW);
134 int luminance = GetLuminance(window_color);
135 return luminance >= 127 ? SettingsPlugin::PlatformBrightness::kLight
137 } else {
138 return GetThemeBrightness();
139 }
140}
unsigned long DWORD
Definition: windows_types.h:22

◆ GetTextScaleFactor()

float flutter::SettingsPlugin::GetTextScaleFactor ( )
protectedvirtual

Definition at line 116 of file settings_plugin.cc.

116 {
117 DWORD text_scale_factor;
118 DWORD text_scale_factor_size = sizeof(text_scale_factor);
119 LONG result = RegGetValue(
120 HKEY_CURRENT_USER, kGetTextScaleFactorRegKey, kGetTextScaleFactorRegValue,
121 RRF_RT_REG_DWORD, nullptr, &text_scale_factor, &text_scale_factor_size);
122
123 if (result == 0) {
124 return text_scale_factor / 100.0;
125 } else {
126 // The current OS does not have text scale factor.
127 return 1.0;
128 }
129}
GAsyncResult * result
#define HKEY_CURRENT_USER
long LONG
Definition: windows_types.h:23

◆ SendSettings()

void flutter::SettingsPlugin::SendSettings ( )

Definition at line 69 of file settings_plugin.cc.

69 {
70 rapidjson::Document settings(rapidjson::kObjectType);
71 auto& allocator = settings.GetAllocator();
72 settings.AddMember(kAlwaysUse24HourFormat, GetAlwaysUse24HourFormat(),
73 allocator);
74 settings.AddMember(kTextScaleFactor, GetTextScaleFactor(), allocator);
75
77 settings.AddMember(kPlatformBrightness, kPlatformBrightnessDark, allocator);
78 } else {
79 settings.AddMember(kPlatformBrightness, kPlatformBrightnessLight,
80 allocator);
81 }
82 channel_->Send(settings);
83}
virtual bool GetAlwaysUse24HourFormat()
virtual PlatformBrightness GetPreferredBrightness()
virtual float GetTextScaleFactor()
static constexpr char kPlatformBrightnessLight[]
static constexpr char kPlatformBrightnessDark[]

◆ StartWatching()

void flutter::SettingsPlugin::StartWatching ( )
virtual

Definition at line 85 of file settings_plugin.cc.

85 {
86 RegOpenKeyEx(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
87 RRF_RT_REG_DWORD, KEY_NOTIFY, &preferred_brightness_reg_hkey_);
88 RegOpenKeyEx(HKEY_CURRENT_USER, kGetTextScaleFactorRegKey, RRF_RT_REG_DWORD,
89 KEY_NOTIFY, &text_scale_factor_reg_hkey_);
90
91 // Start watching when the keys exist.
92 if (preferred_brightness_reg_hkey_ != nullptr) {
94 }
95 if (text_scale_factor_reg_hkey_ != nullptr) {
97 }
98}
virtual void WatchPreferredBrightnessChanged()
virtual void WatchTextScaleFactorChanged()
#define KEY_NOTIFY

◆ StopWatching()

void flutter::SettingsPlugin::StopWatching ( )
virtual

Definition at line 100 of file settings_plugin.cc.

100 {
101 preferred_brightness_changed_watcher_ = nullptr;
102 text_scale_factor_changed_watcher_ = nullptr;
103
104 if (preferred_brightness_reg_hkey_ != nullptr) {
105 RegCloseKey(preferred_brightness_reg_hkey_);
106 }
107 if (text_scale_factor_reg_hkey_ != nullptr) {
108 RegCloseKey(text_scale_factor_reg_hkey_);
109 }
110}

◆ UpdateHighContrastMode()

void flutter::SettingsPlugin::UpdateHighContrastMode ( bool  is_high_contrast)
virtual

Definition at line 169 of file settings_plugin.cc.

169 {
170 is_high_contrast_ = is_high_contrast;
171 SendSettings();
172}

◆ WatchPreferredBrightnessChanged()

void flutter::SettingsPlugin::WatchPreferredBrightnessChanged ( )
protectedvirtual

Definition at line 142 of file settings_plugin.cc.

142 {
143 preferred_brightness_changed_watcher_ =
144 std::make_unique<EventWatcher>([this]() {
145 task_runner_->PostTask([this]() {
146 SendSettings();
148 });
149 });
150
151 RegNotifyChangeKeyValue(
152 preferred_brightness_reg_hkey_, FALSE, REG_NOTIFY_CHANGE_LAST_SET,
153 preferred_brightness_changed_watcher_->GetHandle(), TRUE);
154}
void PostTask(TaskClosure task)
Definition: task_runner.cc:88
return FALSE

◆ WatchTextScaleFactorChanged()

void flutter::SettingsPlugin::WatchTextScaleFactorChanged ( )
protectedvirtual

Definition at line 156 of file settings_plugin.cc.

156 {
157 text_scale_factor_changed_watcher_ = std::make_unique<EventWatcher>([this]() {
158 task_runner_->PostTask([this]() {
159 SendSettings();
161 });
162 });
163
164 RegNotifyChangeKeyValue(
165 text_scale_factor_reg_hkey_, FALSE, REG_NOTIFY_CHANGE_LAST_SET,
166 text_scale_factor_changed_watcher_->GetHandle(), TRUE);
167}

Member Data Documentation

◆ is_high_contrast_

bool flutter::SettingsPlugin::is_high_contrast_ = false
protected

Definition at line 62 of file settings_plugin.h.


The documentation for this class was generated from the following files: