feat: add {get|set}AccentColor on Windows (#48017)

* feat: add setAccentColor on Windows

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* refactor: unify GetSystemAccentColor

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* refactor: remove redundant parsing

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* chore: fixup documentation

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Update docs/api/browser-window.md

Co-authored-by: Will Anderson <andersonw@dropbox.com>

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Update docs/api/base-window.md

Co-authored-by: Will Anderson <andersonw@dropbox.com>

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-08-11 11:17:43 -04:00 committed by GitHub
commit 4b46b6e2f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 265 additions and 24 deletions

View file

@ -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)
@ -1333,6 +1360,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)