| Flutter Windows Embedder |

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 | PlatformBrightness { PlatformBrightness::kDark, PlatformBrightness::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

enum flutter::SettingsPlugin::PlatformBrightness
| strong

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,
61 kChannelName,
62 &JsonMessageCodec::GetInstance())),
63 task_runner_(task_runner) {}

## ◆ ~SettingsPlugin()

flutter::SettingsPlugin::~SettingsPlugin | ( |  | ) |
| virtual

Definition at line 65 of file settings_plugin.cc.

65 {
66 StopWatching();
67 }

References StopWatching().

## Member Function Documentation

## ◆ GetAlwaysUse24HourFormat()

bool flutter::SettingsPlugin::GetAlwaysUse24HourFormat | ( |  | ) |
| protectedvirtual

Definition at line 112 of file settings_plugin.cc.

112 {
113 return Prefer24HourTime(GetUserTimeFormat());
114 }

References flutter::GetUserTimeFormat(), and flutter::Prefer24HourTime().

Referenced by SendSettings().

## ◆ 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
136 : SettingsPlugin::PlatformBrightness::kDark;
137 } else {
138 return GetThemeBrightness();
139 }
140 }

References is_high_contrast_, kDark, and kLight.

Referenced by SendSettings().

## ◆ 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 }

Referenced by SendSettings().

## ◆ 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
76 if (GetPreferredBrightness() == PlatformBrightness::kDark) {
77 settings.AddMember(kPlatformBrightness, kPlatformBrightnessDark, allocator);
78 } else {
79 settings.AddMember(kPlatformBrightness, kPlatformBrightnessLight,
80 allocator);
81 }
82 channel_->Send(settings);
83 }

References GetAlwaysUse24HourFormat(), GetPreferredBrightness(), GetTextScaleFactor(), and kDark.

Referenced by UpdateHighContrastMode(), WatchPreferredBrightnessChanged(), and WatchTextScaleFactorChanged().

## ◆ 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) {
93 WatchPreferredBrightnessChanged();
94 }
95 if (text_scale_factor_reg_hkey_ != nullptr) {
96 WatchTextScaleFactorChanged();
97 }
98 }

References WatchPreferredBrightnessChanged(), and WatchTextScaleFactorChanged().

## ◆ 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 }

Referenced by ~SettingsPlugin().

## ◆ 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 }

References is_high_contrast_, and SendSettings().

## ◆ 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();
147 WatchPreferredBrightnessChanged();
148 });
149 });
150
151 RegNotifyChangeKeyValue(
152 preferred_brightness_reg_hkey_, FALSE, REG_NOTIFY_CHANGE_LAST_SET,
153 preferred_brightness_changed_watcher_->GetHandle(), TRUE);
154 }

References flutter::TaskRunner::PostTask(), and SendSettings().

Referenced by StartWatching().

## ◆ 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();
160 WatchTextScaleFactorChanged();
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 }

References flutter::TaskRunner::PostTask(), and SendSettings().

Referenced by StartWatching().

## Member Data Documentation

## ◆ is_high_contrast_

bool flutter::SettingsPlugin::is_high_contrast_ = false
| protected

Definition at line 62 of file settings_plugin.h.

Referenced by GetPreferredBrightness(), and UpdateHighContrastMode().

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

- shell/platform/windows/settings_plugin.h
- shell/platform/windows/settings_plugin.cc

flutter::SettingsPlugin::PlatformBrightness::kLight
@ kLight
flutter::JsonMessageCodec::GetInstance
static const JsonMessageCodec & GetInstance()
Definition: json_message_codec.cc:17
flutter::SettingsPlugin::WatchTextScaleFactorChanged
virtual void WatchTextScaleFactorChanged()
Definition: settings_plugin.cc:156
flutter::SettingsPlugin::SendSettings
void SendSettings()
Definition: settings_plugin.cc:69
flutter::TaskRunner::PostTask
void PostTask(TaskClosure task)
Definition: task_runner.cc:88
flutter::GetUserTimeFormat
std::wstring GetUserTimeFormat()
Definition: system_utils.cc:101
flutter::SettingsPlugin::is_high_contrast_
bool is_high_contrast_
Definition: settings_plugin.h:62
flutter::Prefer24HourTime
bool Prefer24HourTime(std::wstring time_format)
Definition: system_utils.cc:113
flutter::SettingsPlugin::PlatformBrightness::kDark
@ kDark
flutter::SettingsPlugin::GetTextScaleFactor
virtual float GetTextScaleFactor()
Definition: settings_plugin.cc:116
flutter::SettingsPlugin::GetPreferredBrightness
virtual PlatformBrightness GetPreferredBrightness()
Definition: settings_plugin.cc:131
kChannelName
static constexpr char kChannelName[]
Definition: cursor_handler.cc:13
flutter::SettingsPlugin::StopWatching
virtual void StopWatching()
Definition: settings_plugin.cc:100
flutter::SettingsPlugin::GetAlwaysUse24HourFormat
virtual bool GetAlwaysUse24HourFormat()
Definition: settings_plugin.cc:112
flutter::SettingsPlugin::WatchPreferredBrightnessChanged
virtual void WatchPreferredBrightnessChanged()
Definition: settings_plugin.cc:142