From 03565384e64957118f84855e5b282cfaa56e5107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Sep 2024 09:16:54 +0800 Subject: [PATCH] Chore (macOS): use simplified syntax --- src/detection/cursor/cursor_apple.m | 14 +++++++------- src/detection/monitor/monitor_apple.m | 2 +- src/detection/os/os_apple.m | 6 +++--- src/detection/terminalfont/terminalfont_apple.m | 14 +++++++------- src/detection/wallpaper/wallpaper_apple.m | 8 ++++---- src/detection/wmtheme/wmtheme_apple.m | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/detection/cursor/cursor_apple.m b/src/detection/cursor/cursor_apple.m index 40d4b90c9..29187e11d 100644 --- a/src/detection/cursor/cursor_apple.m +++ b/src/detection/cursor/cursor_apple.m @@ -4,10 +4,10 @@ static void appendColor(FFstrbuf* str, NSDictionary* color) { - int r = (int) (((NSNumber*) [color valueForKey:@"red"]).doubleValue * 255); - int g = (int) (((NSNumber*) [color valueForKey:@"green"]).doubleValue * 255); - int b = (int) (((NSNumber*) [color valueForKey:@"blue"]).doubleValue * 255); - int a = (int) (((NSNumber*) [color valueForKey:@"alpha"]).doubleValue * 255); + int r = (int) (((NSNumber*) color[@"red"]).doubleValue * 255); + int g = (int) (((NSNumber*) color[@"green"]).doubleValue * 255); + int b = (int) (((NSNumber*) color[@"blue"]).doubleValue * 255); + int a = (int) (((NSNumber*) color[@"alpha"]).doubleValue * 255); if (r == 255 && g == 255 && b == 255 && a == 255) ffStrbufAppendS(str, "White"); @@ -32,19 +32,19 @@ void ffDetectCursor(FFCursorResult* result) NSDictionary* color; ffStrbufAppendS(&result->theme, "Fill - "); - if ((color = [dict valueForKey:@"cursorFill"])) + if ((color = dict[@"cursorFill"])) appendColor(&result->theme, color); else ffStrbufAppendS(&result->theme, "Black"); ffStrbufAppendS(&result->theme, ", Outline - "); - if ((color = [dict valueForKey:@"cursorOutline"])) + if ((color = dict[@"cursorOutline"])) appendColor(&result->theme, color); else ffStrbufAppendS(&result->theme, "White"); - NSNumber* mouseDriverCursorSize = [dict valueForKey:@"mouseDriverCursorSize"]; + NSNumber* mouseDriverCursorSize = dict[@"mouseDriverCursorSize"]; if (mouseDriverCursorSize) ffStrbufAppendF(&result->size, "%d", (int) (mouseDriverCursorSize.doubleValue * 32)); else diff --git a/src/detection/monitor/monitor_apple.m b/src/detection/monitor/monitor_apple.m index 70d71eeb6..04163bc7c 100644 --- a/src/detection/monitor/monitor_apple.m +++ b/src/detection/monitor/monitor_apple.m @@ -29,7 +29,7 @@ static bool detectHdrSupportWithNSScreen(FFDisplayResult* display) for (NSScreen* screen in NSScreen.screens) { if (screen == mainScreen) continue; - NSNumber* screenNumber = [screen.deviceDescription valueForKey:@"NSScreenNumber"]; + NSNumber* screenNumber = screen.deviceDescription[@"NSScreenNumber"]; if (screenNumber && screenNumber.longValue == (long) display->id) { #ifdef MAC_OS_X_VERSION_10_15 diff --git a/src/detection/os/os_apple.m b/src/detection/os/os_apple.m index 5a8ef621a..b86202b1e 100644 --- a/src/detection/os/os_apple.m +++ b/src/detection/os/os_apple.m @@ -19,11 +19,11 @@ static void parseSystemVersion(FFOSResult* os) NSString* value; - if((value = [dict valueForKey:@"ProductName"])) + if((value = dict[@"ProductName"])) ffStrbufInitS(&os->name, value.UTF8String); - if((value = [dict valueForKey:@"ProductUserVisibleVersion"])) + if((value = dict[@"ProductUserVisibleVersion"])) ffStrbufInitS(&os->version, value.UTF8String); - if((value = [dict valueForKey:@"ProductBuildVersion"])) + if((value = dict[@"ProductBuildVersion"])) ffStrbufInitS(&os->buildID, value.UTF8String); } diff --git a/src/detection/terminalfont/terminalfont_apple.m b/src/detection/terminalfont/terminalfont_apple.m index 7d6aca282..90fed7fd1 100644 --- a/src/detection/terminalfont/terminalfont_apple.m +++ b/src/detection/terminalfont/terminalfont_apple.m @@ -26,12 +26,12 @@ static void detectIterm2(FFTerminalFontResult* terminalFont) return; } - for(NSDictionary* bookmark in [dict valueForKey:@"New Bookmarks"]) + for(NSDictionary* bookmark in dict[@"New Bookmarks"]) { - if(![[bookmark valueForKey:@"Name"] isEqualToString:@(profile)]) + if(![bookmark[@"Name"] isEqualToString:@(profile)]) continue; - NSString* normalFont = [bookmark valueForKey:@"Normal Font"]; + NSString* normalFont = bookmark[@"Normal Font"]; if(!normalFont) { ffStrbufAppendF(&terminalFont->error, "`Normal Font` key in profile `%s` doesn't exist", profile); @@ -39,10 +39,10 @@ static void detectIterm2(FFTerminalFontResult* terminalFont) } ffFontInitWithSpace(&terminalFont->font, normalFont.UTF8String); - NSNumber* useNonAsciiFont = [bookmark valueForKey:@"Use Non-ASCII Font"]; + NSNumber* useNonAsciiFont = bookmark[@"Use Non-ASCII Font"]; if(useNonAsciiFont.boolValue) { - NSString* nonAsciiFont = [bookmark valueForKey:@"Non Ascii Font"]; + NSString* nonAsciiFont = bookmark[@"Non Ascii Font"]; if (nonAsciiFont) ffFontInitWithSpace(&terminalFont->fallback, nonAsciiFont.UTF8String); } @@ -78,13 +78,13 @@ static void detectWarpTerminal(FFTerminalFontResult* terminalFont) return; } - NSString* fontName = [dict valueForKey:@"FontName"]; + NSString* fontName = dict[@"FontName"]; if(!fontName) fontName = @"Hack"; else fontName = [fontName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\""]]; - NSString* fontSize = [dict valueForKey:@"FontSize"]; + NSString* fontSize = dict[@"FontSize"]; if(!fontSize) fontSize = @"13"; diff --git a/src/detection/wallpaper/wallpaper_apple.m b/src/detection/wallpaper/wallpaper_apple.m index eb330dda1..6780828d3 100644 --- a/src/detection/wallpaper/wallpaper_apple.m +++ b/src/detection/wallpaper/wallpaper_apple.m @@ -18,16 +18,16 @@ const char* ffDetectWallpaper(FFstrbuf* result) NSArray* choices = [dict valueForKeyPath:@"SystemDefault.Desktop.Content.Choices"]; if (choices.count > 0) { - NSDictionary* choice = [choices objectAtIndex:0]; - NSArray* files = [choice valueForKey:@"Files"]; + NSDictionary* choice = choices[0]; + NSArray* files = choice[@"Files"]; if (files.count > 0) { - NSString* file = [[files objectAtIndex: 0] valueForKey: @"relative"]; + NSString* file = files[0][@"relative"]; ffStrbufAppendS(result, [NSURL URLWithString:file].path.UTF8String); } else { - NSString* provider = [choice valueForKey:@"Provider"]; + NSString* provider = choice[@"Provider"]; NSString* builtinPrefix = @"com.apple.wallpaper.choice."; if ([provider hasPrefix:builtinPrefix]) provider = [provider substringFromIndex:builtinPrefix.length]; diff --git a/src/detection/wmtheme/wmtheme_apple.m b/src/detection/wmtheme/wmtheme_apple.m index 08810b6cc..8c43877b1 100644 --- a/src/detection/wmtheme/wmtheme_apple.m +++ b/src/detection/wmtheme/wmtheme_apple.m @@ -15,7 +15,7 @@ bool ffDetectWmTheme(FFstrbuf* themeOrError) return false; } - NSNumber* wmThemeColor = [dict valueForKey:@"AppleAccentColor"]; + NSNumber* wmThemeColor = dict[@"AppleAccentColor"]; if(!wmThemeColor) ffStrbufAppendS(themeOrError, "Multicolor"); else @@ -34,7 +34,7 @@ bool ffDetectWmTheme(FFstrbuf* themeOrError) } } - NSString* wmTheme = [dict valueForKey:@"AppleInterfaceStyle"]; + NSString* wmTheme = dict[@"AppleInterfaceStyle"]; ffStrbufAppendF(themeOrError, " (%s)", wmTheme ? wmTheme.UTF8String : "Light"); return true; }