diff --git a/atom/browser/api/atom_api_system_preferences.cc b/atom/browser/api/atom_api_system_preferences.cc index f7baf715ed84..96efe80c3244 100644 --- a/atom/browser/api/atom_api_system_preferences.cc +++ b/atom/browser/api/atom_api_system_preferences.cc @@ -14,7 +14,11 @@ namespace atom { namespace api { -SystemPreferences::SystemPreferences(v8::Isolate* isolate) { +SystemPreferences::SystemPreferences(v8::Isolate* isolate) +#if defined(OS_WIN) + : color_change_listener_(this) +#endif + { Init(isolate); #if defined(OS_WIN) InitializeWindow(); diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 1d3dbb977912..1c00bfe29c4f 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -24,7 +24,11 @@ namespace atom { namespace api { -class SystemPreferences : public mate::EventEmitter { +class SystemPreferences : public mate::EventEmitter +#if defined(OS_WIN) + , public gfx::SysColorChangeListener +#endif + { public: static mate::Handle Create(v8::Isolate* isolate); @@ -43,8 +47,8 @@ class SystemPreferences : public mate::EventEmitter { void InitializeWindow(); - void OnColorChanged(); - + // gfx::SysColorChangeListener: + void OnSysColorChange() override; #elif defined(OS_MACOSX) using NotificationCallback = base::Callback< @@ -101,9 +105,9 @@ class SystemPreferences : public mate::EventEmitter { std::string current_color_; - bool invertered_color_scheme_ = false; + bool invertered_color_scheme_; - std::unique_ptr color_change_listener_; + gfx::ScopedSysColorChangeListener color_change_listener_; #endif DISALLOW_COPY_AND_ASSIGN(SystemPreferences); }; diff --git a/atom/browser/api/atom_api_system_preferences_win.cc b/atom/browser/api/atom_api_system_preferences_win.cc index 04e216b28eac..c157d5281b78 100644 --- a/atom/browser/api/atom_api_system_preferences_win.cc +++ b/atom/browser/api/atom_api_system_preferences_win.cc @@ -19,21 +19,6 @@ const wchar_t kSystemPreferencesWindowClass[] = namespace api { -class SystemPreferencesColorChangeListener - : public gfx::SysColorChangeListener { - public: - explicit SystemPreferencesColorChangeListener(SystemPreferences* prefs) - : prefs_(prefs) { - } - - void OnSysColorChange() { - prefs_->OnColorChanged(); - } - - private: - SystemPreferences* prefs_; -}; - bool SystemPreferences::IsAeroGlassEnabled() { return ui::win::IsAeroGlassEnabled(); } @@ -57,6 +42,8 @@ std::string SystemPreferences::GetAccentColor() { } void SystemPreferences::InitializeWindow() { + invertered_color_scheme_ = IsInvertedColorScheme(); + WNDCLASSEX window_class; base::win::InitializeWindowClass( kSystemPreferencesWindowClass, @@ -74,10 +61,6 @@ void SystemPreferences::InitializeWindow() { 0, WS_POPUP, 0, 0, 0, 0, 0, 0, instance_, 0); gfx::CheckWindowCreated(window_); gfx::SetWindowUserData(window_, this); - - color_change_listener_.reset( - new gfx::ScopedSysColorChangeListener( - new SystemPreferencesColorChangeListener(this))); } LRESULT CALLBACK SystemPreferences::WndProcStatic(HWND hwnd, @@ -107,7 +90,7 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd, return ::DefWindowProc(hwnd, message, wparam, lparam); } -void SystemPreferences::OnColorChanged() { +void SystemPreferences::OnSysColorChange() { bool new_invertered_color_scheme = IsInvertedColorScheme(); if (new_invertered_color_scheme != invertered_color_scheme_) { invertered_color_scheme_ = new_invertered_color_scheme;