5#include "flutter/shell/platform/windows/settings_plugin.h"
7#include "flutter/shell/platform/common/json_message_codec.h"
8#include "flutter/shell/platform/windows/system_utils.h"
15constexpr char kAlwaysUse24HourFormat[] =
"alwaysUse24HourFormat";
16constexpr char kTextScaleFactor[] =
"textScaleFactor";
17constexpr char kPlatformBrightness[] =
"platformBrightness";
22constexpr wchar_t kGetPreferredBrightnessRegKey[] =
23 L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
24constexpr wchar_t kGetPreferredBrightnessRegValue[] =
L"AppsUseLightTheme";
26constexpr wchar_t kGetTextScaleFactorRegKey[] =
27 L"Software\\Microsoft\\Accessibility";
28constexpr wchar_t kGetTextScaleFactorRegValue[] =
L"TextScaleFactor";
32 int r = GetRValue(
color);
33 int g = GetGValue(
color);
35 return (r + r + r +
b + (g << 2)) >> 3;
40 DWORD use_light_theme;
41 DWORD use_light_theme_size =
sizeof(use_light_theme);
43 kGetPreferredBrightnessRegValue, RRF_RT_REG_DWORD,
44 nullptr, &use_light_theme, &use_light_theme_size);
63 task_runner_(task_runner) {}
70 rapidjson::Document
settings(rapidjson::kObjectType);
71 auto& allocator =
settings.GetAllocator();
87 RRF_RT_REG_DWORD,
KEY_NOTIFY, &preferred_brightness_reg_hkey_);
92 if (preferred_brightness_reg_hkey_ !=
nullptr) {
95 if (text_scale_factor_reg_hkey_ !=
nullptr) {
101 preferred_brightness_changed_watcher_ =
nullptr;
102 text_scale_factor_changed_watcher_ =
nullptr;
104 if (preferred_brightness_reg_hkey_ !=
nullptr) {
105 RegCloseKey(preferred_brightness_reg_hkey_);
107 if (text_scale_factor_reg_hkey_ !=
nullptr) {
108 RegCloseKey(text_scale_factor_reg_hkey_);
117 DWORD text_scale_factor;
118 DWORD text_scale_factor_size =
sizeof(text_scale_factor);
121 RRF_RT_REG_DWORD,
nullptr, &text_scale_factor, &text_scale_factor_size);
124 return text_scale_factor / 100.0;
133 DWORD window_color = GetSysColor(COLOR_WINDOW);
134 int luminance = GetLuminance(window_color);
138 return GetThemeBrightness();
143 preferred_brightness_changed_watcher_ =
144 std::make_unique<EventWatcher>([
this]() {
151 RegNotifyChangeKeyValue(
152 preferred_brightness_reg_hkey_,
FALSE, REG_NOTIFY_CHANGE_LAST_SET,
153 preferred_brightness_changed_watcher_->GetHandle(),
TRUE);
157 text_scale_factor_changed_watcher_ = std::make_unique<EventWatcher>([
this]() {
164 RegNotifyChangeKeyValue(
165 text_scale_factor_reg_hkey_,
FALSE, REG_NOTIFY_CHANGE_LAST_SET,
166 text_scale_factor_changed_watcher_->GetHandle(),
TRUE);
virtual ~SettingsPlugin()
virtual void StartWatching()
virtual void UpdateHighContrastMode(bool is_high_contrast)
virtual void WatchPreferredBrightnessChanged()
virtual bool GetAlwaysUse24HourFormat()
virtual PlatformBrightness GetPreferredBrightness()
SettingsPlugin(BinaryMessenger *messenger, TaskRunner *task_runner)
virtual void WatchTextScaleFactorChanged()
virtual float GetTextScaleFactor()
virtual void StopWatching()
void PostTask(TaskClosure task)
static constexpr char kPlatformBrightnessLight[]
static constexpr char kPlatformBrightnessDark[]
std::wstring GetUserTimeFormat()
bool Prefer24HourTime(std::wstring time_format)
#define HKEY_CURRENT_USER