зеркало из https://github.com/electron/electron.git
Add inverted-color-scheme-changed event
This commit is contained in:
Родитель
223e9d97a0
Коммит
8b16b82ce9
|
@ -16,9 +16,9 @@ namespace api {
|
|||
|
||||
SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
|
||||
Init(isolate);
|
||||
#if defined(OS_WIN)
|
||||
#if defined(OS_WIN)
|
||||
InitializeWindow();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
SystemPreferences::~SystemPreferences() {
|
||||
|
@ -30,6 +30,10 @@ bool SystemPreferences::IsDarkMode() {
|
|||
}
|
||||
#endif
|
||||
|
||||
bool SystemPreferences::IsInvertedColorScheme() {
|
||||
return color_utils::IsInvertedColorScheme();
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<SystemPreferences> SystemPreferences::Create(
|
||||
v8::Isolate* isolate) {
|
||||
|
@ -62,7 +66,7 @@ void SystemPreferences::BuildPrototype(
|
|||
&SystemPreferences::IsSwipeTrackingFromScrollEventsEnabled)
|
||||
#endif
|
||||
.SetMethod("isInvertedColorScheme",
|
||||
&color_utils::IsInvertedColorScheme)
|
||||
&SystemPreferences::IsInvertedColorScheme)
|
||||
.SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
#include "base/values.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/sys_color_change_listener.h"
|
||||
#endif
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
}
|
||||
|
@ -39,6 +43,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
|
||||
void InitializeWindow();
|
||||
|
||||
void OnColorChanged();
|
||||
|
||||
|
||||
#elif defined(OS_MACOSX)
|
||||
using NotificationCallback = base::Callback<
|
||||
|
@ -59,6 +65,7 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
bool IsSwipeTrackingFromScrollEventsEnabled();
|
||||
#endif
|
||||
bool IsDarkMode();
|
||||
bool IsInvertedColorScheme();
|
||||
|
||||
protected:
|
||||
explicit SystemPreferences(v8::Isolate* isolate);
|
||||
|
@ -93,6 +100,10 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences> {
|
|||
HWND window_;
|
||||
|
||||
std::string current_color_;
|
||||
|
||||
bool invertered_color_scheme_ = false;
|
||||
|
||||
std::unique_ptr<gfx::ScopedSysColorChangeListener> color_change_listener_;
|
||||
#endif
|
||||
DISALLOW_COPY_AND_ASSIGN(SystemPreferences);
|
||||
};
|
||||
|
|
|
@ -19,6 +19,21 @@ 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();
|
||||
}
|
||||
|
@ -59,6 +74,10 @@ 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,
|
||||
|
@ -88,6 +107,14 @@ LRESULT CALLBACK SystemPreferences::WndProc(HWND hwnd,
|
|||
return ::DefWindowProc(hwnd, message, wparam, lparam);
|
||||
}
|
||||
|
||||
void SystemPreferences::OnColorChanged() {
|
||||
bool new_invertered_color_scheme = IsInvertedColorScheme();
|
||||
if (new_invertered_color_scheme != invertered_color_scheme_) {
|
||||
Emit("inverted-color-scheme-changed", new_invertered_color_scheme);
|
||||
invertered_color_scheme_ = new_invertered_color_scheme;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
|
Загрузка…
Ссылка в новой задаче