Skip to content

Commit

Permalink
use helper
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jan 3, 2019
1 parent 11a114e commit b8f3b3b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions atom/browser/api/atom_api_system_preferences_mac.mm
Expand Up @@ -104,6 +104,16 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}
}

// Convert color to RGB hex value like "#ABCDEF"
std::string ToRGBHex(NSColor* color) {
NSString* rgbHex = [NSString
stringWithFormat:@"%02X%02X%02X", (int)(color.redComponent * 0xFF),
(int)(color.greenComponent * 0xFF),
(int)(color.blueComponent * 0xFF)];

return std::string([rgbHex UTF8String]);
}

} // namespace

void SystemPreferences::PostNotification(const std::string& name,
Expand Down Expand Up @@ -405,12 +415,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
return "";
}

NSString* rgbHex = [NSString
stringWithFormat:@"%02X%02X%02X", (int)(sysColor.redComponent * 0xFF),
(int)(sysColor.greenComponent * 0xFF),
(int)(sysColor.blueComponent * 0xFF)];

return std::string([rgbHex UTF8String]);
return ToRGBHex(sysColor);
} else {
args->ThrowError(
"This api is not available on MacOS version 10.9 or lower.");
Expand Down

0 comments on commit b8f3b3b

Please sign in to comment.