Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mac support to systemPrefs.getAccentColor() #16251

Merged
merged 2 commits into from Jan 3, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -55,8 +55,10 @@ void SystemPreferences::BuildPrototype(
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "SystemPreferences"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_MACOSX)
.SetMethod("getAccentColor", &SystemPreferences::GetAccentColor)
#endif
#if defined(OS_WIN)
.SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
.SetMethod("getColor", &SystemPreferences::GetColor)
#elif defined(OS_MACOSX)
@@ -49,10 +49,13 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);

#if defined(OS_WIN) || defined(OS_MACOSX)
std::string GetAccentColor();
#endif

#if defined(OS_WIN)
bool IsAeroGlassEnabled();

std::string GetAccentColor();
std::string GetColor(const std::string& color, mate::Arguments* args);

void InitializeWindow();
@@ -13,6 +13,7 @@
#include "atom/browser/mac/dict_util.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
#include "native_mate/object_template_builder.h"
@@ -104,6 +105,14 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}
}

// Convert color to RGBA value like "#ABCDEF"
std::string ToRGBA(NSColor* color) {
This conversation was marked as resolved by codebytere

This comment has been minimized.

Copy link
@miniak

miniak Jan 3, 2019

Contributor

consider doing this instead

#include "base/strings/stringprintf.h"

...

std::string ToRGBHex(NSColor* color) {
  return base::StringPrintf("#%02X%02X%02X", (int)(color.redComponent * 0xFF),
                            (int)(color.greenComponent * 0xFF),
                            (int)(color.blueComponent * 0xFF));
}
return base::StringPrintf(
"%02X%02X%02X%02X", (int)(color.redComponent * 0xFF),
(int)(color.greenComponent * 0xFF), (int)(color.blueComponent * 0xFF),
(int)(color.alphaComponent * 0xFF));
}

} // namespace

void SystemPreferences::PostNotification(const std::string& name,
@@ -378,6 +387,14 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}
}

std::string SystemPreferences::GetAccentColor() {
NSColor* sysColor = nil;
if (@available(macOS 10.14, *))
sysColor = [NSColor controlAccentColor];
This conversation was marked as resolved by codebytere

This comment has been minimized.

Copy link
@miniak

miniak Jan 3, 2019

Contributor

you need to forward declare this as it's macOS SDK 10.14+ only

@interface NSColor (MojaveSDK)
@property (class, strong, readonly) NSColor *controlAccentColor NS_AVAILABLE_MAC(10_14);
@end

This comment has been minimized.

Copy link
@codebytere

codebytere Jan 3, 2019

Author Member

done!


return ToRGBA(sysColor);
}

bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
NSDictionary* options = @{(id)kAXTrustedCheckOptionPrompt : @(prompt)};
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
@@ -37,6 +37,11 @@ typedef NS_ENUM(NSInteger, AVAuthorizationStatusMac) {
(AVMediaType)mediaType API_AVAILABLE(macosx(10.14));
@end

@interface NSColor (MojaveSDK)
@property(class, strong, readonly)
NSColor* controlAccentColor API_AVAILABLE(macosx(10.14));
@end

extern "C" {
#if !defined(MAC_OS_X_VERSION_10_14) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14
@@ -227,7 +227,7 @@ if (browserOptions.transparent) {

[dwm-composition]:https://msdn.microsoft.com/en-us/library/windows/desktop/aa969540.aspx

### `systemPreferences.getAccentColor()` _Windows_
### `systemPreferences.getAccentColor()` _Windows_ _macOS_

Returns `String` - The users current system wide accent color preference in RGBA
hexadecimal form.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.