diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index b948cb42630a6..38672a4512818 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -291,7 +291,7 @@ This API is only available on macOS 10.14 Mojave or newer. * `window-frame` - Window frame. * `window-text` - Text in windows. * On **macOS** - * `alternate-selected-control-text` - The text on a selected surface in a list or table. + * `alternate-selected-control-text` - The text on a selected surface in a list or table. _deprecated_ * `control-background` - The background of a large interface element, such as a browser or table. * `control` - The surface of a control. * `control-text` -The text of a control that isn’t disabled. @@ -310,7 +310,7 @@ This API is only available on macOS 10.14 Mojave or newer. * `selected-content-background` - The background for selected content in a key window or view. * `selected-control` - The surface of a selected control. * `selected-control-text` - The text of a selected control. - * `selected-menu-item` - The text of a selected menu. + * `selected-menu-item-text` - The text of a selected menu. * `selected-text-background` - The background of selected text. * `selected-text` - Selected text. * `separator` - A separator between different sections of content. @@ -328,6 +328,8 @@ This API is only available on macOS 10.14 Mojave or newer. Returns `String` - The system color setting in RGB hexadecimal form (`#ABCDEF`). 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`. + [windows-colors]:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724371(v=vs.85).aspx [macos-colors]:https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color#dynamic-system-colors diff --git a/shell/browser/api/atom_api_system_preferences.h b/shell/browser/api/atom_api_system_preferences.h index 22b576334480c..a240f5bbcc483 100644 --- a/shell/browser/api/atom_api_system_preferences.h +++ b/shell/browser/api/atom_api_system_preferences.h @@ -13,6 +13,7 @@ #include "native_mate/handle.h" #include "shell/browser/api/event_emitter.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/node_includes.h" #include "shell/common/promise_util.h" #if defined(OS_WIN) @@ -52,7 +53,8 @@ class SystemPreferences : public mate::EventEmitter #if defined(OS_WIN) || defined(OS_MACOSX) std::string GetAccentColor(); - std::string GetColor(const std::string& color, mate::Arguments* args); + std::string GetColor(gin_helper::ErrorThrower thrower, + const std::string& color); #endif #if defined(OS_WIN) bool IsAeroGlassEnabled(); diff --git a/shell/browser/api/atom_api_system_preferences_mac.mm b/shell/browser/api/atom_api_system_preferences_mac.mm index 079db55476008..2171993bed4b8 100644 --- a/shell/browser/api/atom_api_system_preferences_mac.mm +++ b/shell/browser/api/atom_api_system_preferences_mac.mm @@ -503,19 +503,25 @@ AVMediaType ParseMediaType(const std::string& media_type) { return AXIsProcessTrustedWithOptions((CFDictionaryRef)options); } -std::string SystemPreferences::GetColor(const std::string& color, - mate::Arguments* args) { +std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower, + const std::string& color) { NSColor* sysColor = nil; if (color == "alternate-selected-control-text") { sysColor = [NSColor alternateSelectedControlTextColor]; + EmitDeprecationWarning(node::Environment::GetCurrent(thrower.isolate()), + "Use selected-content-background instead.", + "electron"); } else if (color == "control-background") { sysColor = [NSColor controlBackgroundColor]; } else if (color == "control") { sysColor = [NSColor controlColor]; } else if (color == "control-text") { sysColor = [NSColor controlTextColor]; - } else if (color == "disabled-control") { + } else if (color == "disabled-control-text") { sysColor = [NSColor disabledControlTextColor]; + EmitDeprecationWarning(node::Environment::GetCurrent(thrower.isolate()), + "Use a color that matches the semantics being used.", + "electron"); } else if (color == "find-highlight") { if (@available(macOS 10.14, *)) sysColor = [NSColor findHighlightColor]; @@ -580,11 +586,12 @@ AVMediaType ParseMediaType(const std::string& media_type) { } else if (color == "window-frame-text") { sysColor = [NSColor windowFrameTextColor]; } else { - args->ThrowError("Unknown color: " + color); - return ""; + thrower.ThrowError("Unknown color: " + color); } - return base::SysNSStringToUTF8([sysColor hexadecimalValue]); + if (sysColor) + return base::SysNSStringToUTF8([sysColor hexadecimalValue]); + return ""; } std::string SystemPreferences::GetMediaAccessStatus( diff --git a/spec-main/api-system-preferences-spec.ts b/spec-main/api-system-preferences-spec.ts index 8c636b55c90f1..85e776995dff1 100644 --- a/spec-main/api-system-preferences-spec.ts +++ b/spec-main/api-system-preferences-spec.ts @@ -134,6 +134,58 @@ describe('systemPreferences module', () => { }) }) + ifdescribe(process.platform === 'darwin')('systemPreferences.getColor(color)', () => { + it('throws on invalid colors', () => { + const color = 'bad-color' + expect(() => { + systemPreferences.getColor(color as any) + }).to.throw(`Unknown color: ${color}`) + }) + + it('returns a valid color', () => { + const colors = [ + 'alternate-selected-control-text', + 'control-background', + 'control', + 'control-text', + 'disabled-control-text', + 'find-highlight', + 'grid', + 'header-text', + 'highlight', + 'keyboard-focus-indicator', + 'label', + 'link', + 'placeholder-text', + 'quaternary-label', + 'scrubber-textured-background', + 'secondary-label', + 'selected-content-background', + 'selected-control', + 'selected-control-text', + 'selected-menu-item-text', + 'selected-text-background', + 'selected-text', + 'separator', + 'shadow', + 'tertiary-label', + 'text-background', + 'text', + 'under-page-background', + 'unemphasized-selected-content-background', + 'unemphasized-selected-text-background', + 'unemphasized-selected-text', + 'window-background', + 'window-frame-text' + ] + + colors.forEach(color => { + const sysColor = systemPreferences.getColor(color as any) + expect(sysColor).to.be.a('string') + }) + }) + }) + ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => { it('has an appLevelAppearance property', () => { expect(systemPreferences).to.have.property('appLevelAppearance')