feat: add mac support to systemPrefs.getAccentColor() (#16251)
* feat: add mac support to systemPrefs.getAccentColor() * note 10.14 retriction
This commit is contained in:
parent
5c378de22f
commit
439ba5116f
5 changed files with 32 additions and 3 deletions
|
@ -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 @@ std::string ConvertAuthorizationStatus(AVAuthorizationStatusMac status) {
|
|||
}
|
||||
}
|
||||
|
||||
// Convert color to RGBA value like "#ABCDEF"
|
||||
std::string ToRGBA(NSColor* color) {
|
||||
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 @@ void SystemPreferences::SetUserDefault(const std::string& name,
|
|||
}
|
||||
}
|
||||
|
||||
std::string SystemPreferences::GetAccentColor() {
|
||||
NSColor* sysColor = nil;
|
||||
if (@available(macOS 10.14, *))
|
||||
sysColor = [NSColor controlAccentColor];
|
||||
|
||||
return ToRGBA(sysColor);
|
||||
}
|
||||
|
||||
bool SystemPreferences::IsTrustedAccessibilityClient(bool prompt) {
|
||||
NSDictionary* options = @{(id)kAXTrustedCheckOptionPrompt : @(prompt)};
|
||||
return AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue