From 66c8a42d001b4e0495909954e83d0991bda7d080 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Fri, 7 Aug 2026 03:17:57 +0000
Subject: [PATCH 34/38] terminalfont (Apple): use dictionaryWithContentsOfFile
 and valueForKey

Avoids the NSURL/error-based plist loader and Objective-C subscripting
literal syntax; guard the iTerm2 bookmark lookup behind a 10.5 check
since it breaks linkage on 10.4.

Ported from https://github.com/macos-powerpc/powerpc-ports/blob/main/sysutils/fastfetch/files/0012-Misc-fixes-for-legacy-systems.patch
---
 .../terminalfont/terminalfont_apple.m         | 45 +++++++------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/src/detection/terminalfont/terminalfont_apple.m b/src/detection/terminalfont/terminalfont_apple.m
index c3011846f..b229f44b1 100644
--- a/src/detection/terminalfont/terminalfont_apple.m
+++ b/src/detection/terminalfont/terminalfont_apple.m
@@ -5,7 +5,8 @@
 
 #include <stdlib.h>
 #include <string.h>
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
 
 static void detectIterm2(FFTerminalFontResult* terminalFont)
 {
@@ -16,38 +17,32 @@ static void detectIterm2(FFTerminalFontResult* terminalFont)
         return;
     }
 
-    NSError* error;
-    NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/com.googlecode.iterm2.plist", instance.state.platform.homeDir.chars];
-    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
-                                       error:&error];
-    if(error)
-    {
-        ffStrbufAppendS(&terminalFont->error, error.localizedDescription.UTF8String);
-        return;
-    }
+    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.googlecode.iterm2.plist"]];
 
-    for(NSDictionary* bookmark in dict[@"New Bookmarks"])
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // This chunk of code breaks linkage on 10.4
+    for(NSDictionary* bookmark in [dict valueForKey:@"New Bookmarks"])
     {
-        if(![bookmark[@"Name"] isEqualToString:@(profile)])
+        if(![[bookmark valueForKey:@"Name"] isEqualToString:[NSString stringWithUTF8String:profile]])
             continue;
 
-        NSString* normalFont = bookmark[@"Normal Font"];
+        NSString* normalFont = [bookmark valueForKey:@"Normal Font"];
         if(!normalFont)
         {
             ffStrbufAppendF(&terminalFont->error, "`Normal Font` key in profile `%s` doesn't exist", profile);
             return;
         }
-        ffFontInitWithSpace(&terminalFont->font, normalFont.UTF8String);
+        ffFontInitWithSpace(&terminalFont->font, [normalFont UTF8String]);
 
-        NSNumber* useNonAsciiFont = bookmark[@"Use Non-ASCII Font"];
-        if(useNonAsciiFont.boolValue)
+        NSNumber* useNonAsciiFont = [bookmark valueForKey:@"Use Non-ASCII Font"];
+        if([useNonAsciiFont boolValue])
         {
-            NSString* nonAsciiFont = bookmark[@"Non Ascii Font"];
+            NSString* nonAsciiFont = [bookmark valueForKey:@"Non Ascii Font"];
             if (nonAsciiFont)
-                ffFontInitWithSpace(&terminalFont->fallback, nonAsciiFont.UTF8String);
+                ffFontInitWithSpace(&terminalFont->fallback, [nonAsciiFont UTF8String]);
         }
         return;
     }
+#endif
 
     ffStrbufAppendF(&terminalFont->error, "find profile `%s` bookmark failed", profile);
 }
@@ -68,23 +63,15 @@ static void detectAppleTerminal(FFTerminalFontResult* terminalFont)
 
 static void detectWarpTerminal(FFTerminalFontResult* terminalFont)
 {
-    NSError* error;
-    NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/dev.warp.Warp-Stable.plist", instance.state.platform.homeDir.chars];
-    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
-                                       error:&error];
-    if(error)
-    {
-        ffStrbufAppendS(&terminalFont->error, error.localizedDescription.UTF8String);
-        return;
-    }
+    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/dev.warp.Warp-Stable.plist"]];
 
-    NSString* fontName = dict[@"FontName"];
+    NSString* fontName = [dict valueForKey:@"FontName"];
     if(!fontName)
         fontName = @"Hack";
     else
         fontName = [fontName stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\""]];
 
-    NSString* fontSize = dict[@"FontSize"];
+    NSString* fontSize = [dict valueForKey:@"FontSize"];
     if(!fontSize)
         fontSize = @"13";
 
-- 
2.43.0

