Merge pull request #8568 from electron/initialize-color-listener-after-app-is-ready

Initialize color listener after app is ready
This commit is contained in:
Kevin Sawicki 2017-02-03 09:31:58 -08:00 committed by GitHub
commit 4abbd65628
3 changed files with 24 additions and 6 deletions

View file

@ -14,11 +14,7 @@ namespace atom {
namespace api {
SystemPreferences::SystemPreferences(v8::Isolate* isolate)
#if defined(OS_WIN)
: color_change_listener_(this)
#endif
{
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
Init(isolate);
#if defined(OS_WIN)
InitializeWindow();
@ -26,6 +22,9 @@ SystemPreferences::SystemPreferences(v8::Isolate* isolate)
}
SystemPreferences::~SystemPreferences() {
#if defined(OS_WIN)
Browser::Get()->RemoveObserver(this);
#endif
}
#if !defined(OS_MACOSX)

View file

@ -13,6 +13,8 @@
#include "native_mate/handle.h"
#if defined(OS_WIN)
#include "atom/browser/browser.h"
#include "atom/browser/browser_observer.h"
#include "ui/gfx/sys_color_change_listener.h"
#endif
@ -26,6 +28,7 @@ namespace api {
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
#if defined(OS_WIN)
, public BrowserObserver
, public gfx::SysColorChangeListener
#endif
{
@ -51,6 +54,9 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
// gfx::SysColorChangeListener:
void OnSysColorChange() override;
// BrowserObserver:
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
#elif defined(OS_MACOSX)
using NotificationCallback = base::Callback<
void(const std::string&, const base::DictionaryValue&)>;
@ -111,7 +117,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
bool invertered_color_scheme_;
gfx::ScopedSysColorChangeListener color_change_listener_;
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
#endif
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
};

View file

@ -117,6 +117,14 @@ std::string SystemPreferences::GetColor(const std::string& color,
void SystemPreferences::InitializeWindow() {
invertered_color_scheme_ = IsInvertedColorScheme();
// Wait until app is ready before creating sys color listener
// Creating this listener before the app is ready causes global shortcuts
// to not fire
if (Browser::Get()->is_ready())
color_change_listener_.reset(new gfx::ScopedSysColorChangeListener(this));
else
Browser::Get()->AddObserver(this);
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
kSystemPreferencesWindowClass,
@ -172,6 +180,11 @@ void SystemPreferences::OnSysColorChange() {
Emit("color-changed");
}
void SystemPreferences::OnFinishLaunching(
const base::DictionaryValue& launch_info) {
color_change_listener_.reset(new gfx::ScopedSysColorChangeListener(this));
}
} // namespace api
} // namespace atom