Initialize color listener after app is ready
This commit is contained in:
parent
62a400b7d6
commit
5973aa36ad
3 changed files with 24 additions and 6 deletions
|
@ -14,11 +14,7 @@ namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
SystemPreferences::SystemPreferences(v8::Isolate* isolate)
|
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
|
||||||
#if defined(OS_WIN)
|
|
||||||
: color_change_listener_(this)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
Init(isolate);
|
Init(isolate);
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
InitializeWindow();
|
InitializeWindow();
|
||||||
|
@ -26,6 +22,9 @@ SystemPreferences::SystemPreferences(v8::Isolate* isolate)
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemPreferences::~SystemPreferences() {
|
SystemPreferences::~SystemPreferences() {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
Browser::Get()->RemoveObserver(this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(OS_MACOSX)
|
#if !defined(OS_MACOSX)
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
#include "atom/browser/browser.h"
|
||||||
|
#include "atom/browser/browser_observer.h"
|
||||||
#include "ui/gfx/sys_color_change_listener.h"
|
#include "ui/gfx/sys_color_change_listener.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ namespace api {
|
||||||
|
|
||||||
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
, public BrowserObserver
|
||||||
, public gfx::SysColorChangeListener
|
, public gfx::SysColorChangeListener
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -51,6 +54,9 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||||
// gfx::SysColorChangeListener:
|
// gfx::SysColorChangeListener:
|
||||||
void OnSysColorChange() override;
|
void OnSysColorChange() override;
|
||||||
|
|
||||||
|
// BrowserObserver:
|
||||||
|
void OnFinishLaunching(const base::DictionaryValue& launch_info) override;
|
||||||
|
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
using NotificationCallback = base::Callback<
|
using NotificationCallback = base::Callback<
|
||||||
void(const std::string&, const base::DictionaryValue&)>;
|
void(const std::string&, const base::DictionaryValue&)>;
|
||||||
|
@ -111,7 +117,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
|
||||||
|
|
||||||
bool invertered_color_scheme_;
|
bool invertered_color_scheme_;
|
||||||
|
|
||||||
gfx::ScopedSysColorChangeListener color_change_listener_;
|
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
||||||
#endif
|
#endif
|
||||||
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,6 +117,14 @@ std::string SystemPreferences::GetColor(const std::string& color,
|
||||||
void SystemPreferences::InitializeWindow() {
|
void SystemPreferences::InitializeWindow() {
|
||||||
invertered_color_scheme_ = IsInvertedColorScheme();
|
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;
|
WNDCLASSEX window_class;
|
||||||
base::win::InitializeWindowClass(
|
base::win::InitializeWindowClass(
|
||||||
kSystemPreferencesWindowClass,
|
kSystemPreferencesWindowClass,
|
||||||
|
@ -172,6 +180,11 @@ void SystemPreferences::OnSysColorChange() {
|
||||||
Emit("color-changed");
|
Emit("color-changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SystemPreferences::OnFinishLaunching(
|
||||||
|
const base::DictionaryValue& launch_info) {
|
||||||
|
color_change_listener_.reset(new gfx::ScopedSysColorChangeListener(this));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue