feat: add {get|set}AccentColor
on Windows (#47741)
* feat: add setAccentColor on Windows * refactor: unify GetSystemAccentColor * refactor: remove redundant parsing * chore: fixup documentation * Update docs/api/browser-window.md Co-authored-by: Will Anderson <andersonw@dropbox.com> * Update docs/api/base-window.md Co-authored-by: Will Anderson <andersonw@dropbox.com> --------- Co-authored-by: Will Anderson <andersonw@dropbox.com>
This commit is contained in:
parent
2cfccac074
commit
5c98e3609f
13 changed files with 265 additions and 24 deletions
|
@ -1089,6 +1089,33 @@ void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) {
|
|||
bool BaseWindow::IsSnapped() const {
|
||||
return window_->IsSnapped();
|
||||
}
|
||||
|
||||
void BaseWindow::SetAccentColor(gin_helper::Arguments* args) {
|
||||
bool accent_color = false;
|
||||
std::string accent_color_string;
|
||||
if (args->GetNext(&accent_color_string)) {
|
||||
std::optional<SkColor> maybe_color = ParseCSSColor(accent_color_string);
|
||||
if (maybe_color.has_value()) {
|
||||
window_->SetAccentColor(maybe_color.value());
|
||||
window_->UpdateWindowAccentColor(window_->IsActive());
|
||||
}
|
||||
} else if (args->GetNext(&accent_color)) {
|
||||
window_->SetAccentColor(accent_color);
|
||||
window_->UpdateWindowAccentColor(window_->IsActive());
|
||||
} else {
|
||||
args->ThrowError(
|
||||
"Invalid accent color value - must be a string or boolean");
|
||||
}
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> BaseWindow::GetAccentColor() const {
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
auto accent_color = window_->GetAccentColor();
|
||||
|
||||
if (std::holds_alternative<bool>(accent_color))
|
||||
return v8::Boolean::New(isolate, std::get<bool>(accent_color));
|
||||
return gin::StringToV8(isolate, std::get<std::string>(accent_color));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
|
@ -1277,6 +1304,8 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
|||
#if BUILDFLAG(IS_WIN)
|
||||
.SetMethod("isSnapped", &BaseWindow::IsSnapped)
|
||||
.SetProperty("snapped", &BaseWindow::IsSnapped)
|
||||
.SetMethod("setAccentColor", &BaseWindow::SetAccentColor)
|
||||
.SetMethod("getAccentColor", &BaseWindow::GetAccentColor)
|
||||
.SetMethod("hookWindowMessage", &BaseWindow::HookWindowMessage)
|
||||
.SetMethod("isWindowMessageHooked", &BaseWindow::IsWindowMessageHooked)
|
||||
.SetMethod("unhookWindowMessage", &BaseWindow::UnhookWindowMessage)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue