15 constexpr
char kAlwaysUse24HourFormat[] =
"alwaysUse24HourFormat";
16 constexpr
char kTextScaleFactor[] =
"textScaleFactor";
17 constexpr
char kPlatformBrightness[] =
"platformBrightness";
19 constexpr
char kPlatformBrightnessDark[] =
"dark";
20 constexpr
char kPlatformBrightnessLight[] =
"light";
22 constexpr
wchar_t kGetPreferredBrightnessRegKey[] =
23 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
24 constexpr
wchar_t kGetPreferredBrightnessRegValue[] = L
"AppsUseLightTheme";
26 constexpr
wchar_t kGetTextScaleFactorRegKey[] =
27 L
"Software\\Microsoft\\Accessibility";
28 constexpr
wchar_t kGetTextScaleFactorRegValue[] = L
"TextScaleFactor";
31 int GetLuminance(DWORD color) {
32 int r = GetRValue(color);
33 int g = GetGValue(color);
34 int b = GetBValue(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);
42 LONG result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
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();
77 settings.AddMember(kPlatformBrightness, kPlatformBrightnessDark, allocator);
79 settings.AddMember(kPlatformBrightness, kPlatformBrightnessLight,
82 channel_->Send(settings);
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_);
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);
119 LONG result = RegGetValue(
120 HKEY_CURRENT_USER, kGetTextScaleFactorRegKey, kGetTextScaleFactorRegValue,
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);