Chore (macOS): use simplified syntax

This commit is contained in:
李通洲
2024-09-27 09:16:54 +08:00
parent a3a4f0a64a
commit 03565384e6
6 changed files with 24 additions and 24 deletions
+7 -7
View File
@@ -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
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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);
}
@@ -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";
+4 -4
View File
@@ -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];
+2 -2
View File
@@ -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;
}