mirror of
https://github.com/electron/electron.git
synced 2026-01-11 00:18:02 -05:00
feat: add SF Symbol support to NativeImage::CreateFromNamedImage (#48772)
* feat: add SF Symbol support to NativeImage::CreateFromNamedImage Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com> * use obj-c name in NSImage constructor Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com> * add test for named symbol image Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com> * apply suggested simplification Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com> * fix: support NX cocoa prefix Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: TheCommieAxolotl <87679354+TheCommieAxolotl@users.noreply.github.com>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user