feat: add SF Symbol support to NativeImage::CreateFromNamedImage (#48203)

* feat: add SF Symbol support to NativeImage::CreateFromNamedImage

* use obj-c name in NSImage constructor

* add test for named symbol image

* apply suggested simplification

* fix: support NX cocoa prefix
This commit is contained in:
axolotl
2025-11-04 21:15:34 +11:00
committed by GitHub
parent d7727c9ec2
commit 5bd45a6a28
3 changed files with 17 additions and 4 deletions

View File

@@ -120,9 +120,18 @@ gin_helper::Handle<NativeImage> NativeImage::CreateFromNamedImage(
name.erase(pos, to_remove.length());
}
NSImage* image = [NSImage imageNamed:base::SysUTF8ToNSString(name)];
NSImage* image = nil;
NSString* ns_name = base::SysUTF8ToNSString(name);
if (!image.valid) {
// Treat non-Cocoa-prefixed names as SF Symbols first.
if (!base::StartsWith(name, "NS") && !base::StartsWith(name, "NX")) {
image = [NSImage imageWithSystemSymbolName:ns_name
accessibilityDescription:nil];
} else {
image = [NSImage imageNamed:ns_name];
}
if (!image || !image.valid) {
return CreateEmpty(args->isolate());
}