fix: NSImageName string conversion (#23467)
This commit is contained in:
parent
392ea320cf
commit
6114518463
4 changed files with 19 additions and 8 deletions
|
@ -33,12 +33,24 @@ double safeShift(double in, double def) {
|
|||
return def;
|
||||
}
|
||||
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(
|
||||
gin::Arguments* args,
|
||||
const std::string& name) {
|
||||
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(gin::Arguments* args,
|
||||
std::string name) {
|
||||
@autoreleasepool {
|
||||
std::vector<double> hsl_shift;
|
||||
|
||||
// The string representations of NSImageNames don't match the strings
|
||||
// themselves; they instead follow the following pattern:
|
||||
// * NSImageNameActionTemplate -> "NSActionTemplate"
|
||||
// * NSImageNameMultipleDocuments -> "NSMultipleDocuments"
|
||||
// To account for this, we strip out "ImageName" from the passed string.
|
||||
std::string to_remove("ImageName");
|
||||
size_t pos = name.find(to_remove);
|
||||
if (pos != std::string::npos) {
|
||||
name.erase(pos, to_remove.length());
|
||||
}
|
||||
|
||||
NSImage* image = [NSImage imageNamed:base::SysUTF8ToNSString(name)];
|
||||
|
||||
if (!image.valid) {
|
||||
return CreateEmpty(args->isolate());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue