From d002f16157bbc7f4bc70f2db6edde21d74c02276 Mon Sep 17 00:00:00 2001 From: ILikeTeaALot <25405052+ILikeTeaALot@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:56:16 +0100 Subject: [PATCH] feat: `systemPreferences.getColor` should return RGBA instead of RGB (#38960) * fix: return RGBA hex value from `SystemPreferences.getColor` * docs: update docs to match changes of last commit * fix: GetColor on windows now returns RGBA too * fix: update tests for getColor RGBA on Windows --------- Co-authored-by: John Kleinschmidt --- docs/api/system-preferences.md | 2 +- shell/browser/api/electron_api_system_preferences_mac.mm | 2 +- shell/browser/api/electron_api_system_preferences_win.cc | 2 +- spec/api-system-preferences-spec.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index ab0fafd1ed70..1fea0e3fbc0b 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -306,7 +306,7 @@ This API is only available on macOS 10.14 Mojave or newer. * `window-background` - The background of a window. * `window-frame-text` - The text in the window's titlebar area. -Returns `string` - The system color setting in RGB hexadecimal form (`#ABCDEF`). +Returns `string` - The system color setting in RGBA hexadecimal form (`#RRGGBBAA`). See the [Windows docs][windows-colors] and the [macOS docs][macos-colors] for more details. The following colors are only available on macOS 10.14: `find-highlight`, `selected-content-background`, `separator`, `unemphasized-selected-content-background`, `unemphasized-selected-text-background`, and `unemphasized-selected-text`. diff --git a/shell/browser/api/electron_api_system_preferences_mac.mm b/shell/browser/api/electron_api_system_preferences_mac.mm index df2868ac9935..0cdf585d1697 100644 --- a/shell/browser/api/electron_api_system_preferences_mac.mm +++ b/shell/browser/api/electron_api_system_preferences_mac.mm @@ -540,7 +540,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower, } if (sysColor) - return ToRGBHex(skia::NSSystemColorToSkColor(sysColor)); + return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor)); return ""; } diff --git a/shell/browser/api/electron_api_system_preferences_win.cc b/shell/browser/api/electron_api_system_preferences_win.cc index 982edd2131c6..1e05b697d1b3 100644 --- a/shell/browser/api/electron_api_system_preferences_win.cc +++ b/shell/browser/api/electron_api_system_preferences_win.cc @@ -133,7 +133,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower, }); if (const auto* iter = Lookup.find(color); iter != Lookup.end()) - return ToRGBHex(color_utils::GetSysSkColor(iter->second)); + return ToRGBAHex(color_utils::GetSysSkColor(iter->second)); thrower.ThrowError("Unknown color: " + color); return ""; diff --git a/spec/api-system-preferences-spec.ts b/spec/api-system-preferences-spec.ts index d5a205aec073..adedba89532f 100644 --- a/spec/api-system-preferences-spec.ts +++ b/spec/api-system-preferences-spec.ts @@ -17,8 +17,8 @@ describe('systemPreferences module', () => { }).to.throw('Unknown color: not-a-color'); }); - it('returns a hex RGB color string', () => { - expect(systemPreferences.getColor('window')).to.match(/^#[0-9A-F]{6}$/i); + it('returns a hex RGBA color string', () => { + expect(systemPreferences.getColor('window')).to.match(/^#[0-9A-F]{8}$/i); }); });