Skip to content

Commit

Permalink
feat: systemPreferences.getColor should return RGBA instead of RGB (#…
Browse files Browse the repository at this point in the history
…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 <jkleinsc@electronjs.org>
  • Loading branch information
ILikeTeaALot and jkleinsc committed Sep 28, 2023
1 parent dd7395e commit d002f16
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api/system-preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_system_preferences_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}

if (sysColor)
return ToRGBHex(skia::NSSystemColorToSkColor(sysColor));
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor));
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_system_preferences_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
4 changes: 2 additions & 2 deletions spec/api-system-preferences-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit d002f16

Please sign in to comment.