From 78f5a91f370dd0eea6d6ef4ff9cb902c23e6d96f Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Mon, 4 Nov 2024 08:31:15 +0800
Subject: [PATCH 12/12] Misc fixes for legacy systems

---
 CMakeLists.txt                                | 32 ++++------
 src/common/processing_linux.c                 |  7 ++-
 src/detection/bluetooth/bluetooth_apple.m     | 13 +++-
 src/detection/camera/camera_apple.m           |  4 ++
 src/detection/cursor/cursor_apple.m           | 36 ++++++-----
 src/detection/displayserver/displayserver.c   | 22 +++++++
 src/detection/displayserver/displayserver.h   | 11 ++++
 .../displayserver/displayserver_apple.c       | 63 ++++++++++++++++++-
 src/detection/font/font_apple.m               | 13 +++-
 src/detection/host/host_apple.c               |  4 +-
 src/detection/memory/memory_apple.c           |  2 +
 src/detection/os/os_apple.m                   | 34 ++++++----
 .../physicalmemory/physicalmemory_apple.m     | 57 +++++++++++------
 .../terminalfont/terminalfont_apple.m         | 45 +++++--------
 src/detection/wallpaper/wallpaper_apple.m     | 16 +++--
 src/detection/wmtheme/wmtheme_apple.m         | 28 +++++----
 src/util/apple/osascript.h                    | 10 +++
 src/util/apple/osascript.m                    | 16 ++---
 src/util/kmod.c                               |  9 +++
 src/util/platform/FFPlatform_unix.c           |  5 +-
 20 files changed, 297 insertions(+), 130 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc33bf5b..09ae13a5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -132,10 +132,10 @@ else()
     message(STATUS "Threads type: disabled")
 endif()
 
-set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type")
+set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Wno-error=uninitialized -Werror=return-type")
 
 set(CMAKE_C_STANDARD 11)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration -Wno-error=int-conversion")
 
 if(WIN32 OR ENABLE_DIRECTX_HEADERS)
     enable_language(CXX)
@@ -156,7 +156,7 @@ if(ENABLE_ASAN)
 endif()
 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -fstack-protector-all -fno-delete-null-pointer-checks")
-if(NOT WIN32)
+if(NOT WIN32 AND NOT APPLE)
     set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
 endif()
 
@@ -842,11 +842,11 @@ elseif(APPLE)
         src/common/sysctl.c
         src/detection/battery/battery_apple.c
         src/detection/bios/bios_apple.c
-        src/detection/bluetooth/bluetooth_apple.m
-        src/detection/bluetoothradio/bluetoothradio_apple.m
+        src/detection/bluetooth/bluetooth_nosupport.c
+        src/detection/bluetoothradio/bluetoothradio_nosupport.c
         src/detection/board/board_apple.c
         src/detection/bootmgr/bootmgr_apple.c
-        src/detection/brightness/brightness_apple.c
+        src/detection/brightness/brightness_nosupport.c
         src/detection/btrfs/btrfs_nosupport.c
         src/detection/chassis/chassis_nosupport.c
         src/detection/cpu/cpu_apple.c
@@ -871,15 +871,15 @@ elseif(APPLE)
         src/detection/libc/libc_apple.c
         src/detection/locale/locale_linux.c
         src/detection/localip/localip_linux.c
-        src/detection/gamepad/gamepad_apple.c
-        src/detection/media/media_apple.m
+        src/detection/gamepad/gamepad_nosupport.c
+        src/detection/media/media_nosupport.c
         src/detection/memory/memory_apple.c
         src/detection/mouse/mouse_apple.c
         src/detection/netio/netio_bsd.c
         src/detection/opengl/opengl_apple.c
         src/detection/os/os_apple.m
         src/detection/packages/packages_apple.c
-        src/detection/poweradapter/poweradapter_apple.c
+        src/detection/poweradapter/poweradapter_nosupport.c
         src/detection/processes/processes_bsd.c
         src/detection/sound/sound_apple.c
         src/detection/swap/swap_apple.c
@@ -891,7 +891,7 @@ elseif(APPLE)
         src/detection/uptime/uptime_bsd.c
         src/detection/users/users_linux.c
         src/detection/wallpaper/wallpaper_apple.m
-        src/detection/wifi/wifi_apple.m
+        src/detection/wifi/wifi_nosupport.c
         src/detection/wm/wm_apple.c
         src/detection/de/de_nosupport.c
         src/detection/wmtheme/wmtheme_apple.m
@@ -1389,25 +1389,17 @@ if(LINUX)
     endif()
 elseif(APPLE)
     target_link_libraries(libfastfetch
-        PRIVATE "-framework AVFoundation"
         PRIVATE "-framework Cocoa"
         PRIVATE "-framework CoreFoundation"
         PRIVATE "-framework CoreAudio"
         PRIVATE "-framework CoreMedia"
         PRIVATE "-framework CoreVideo"
-        PRIVATE "-framework CoreWLAN"
         PRIVATE "-framework IOBluetooth"
         PRIVATE "-framework IOKit"
-        PRIVATE "-framework Metal"
         PRIVATE "-framework OpenGL"
-        PRIVATE "-framework OpenCL"
         PRIVATE "-framework SystemConfiguration"
-        PRIVATE "-weak_framework CoreDisplay"
-
-        PRIVATE "-F /System/Library/PrivateFrameworks"
-        PRIVATE "-weak_framework DisplayServices"
-        PRIVATE "-weak_framework MediaRemote"
-        PRIVATE "-weak_framework Apple80211"
+        PRIVATE "-framework DisplayServices"
+        PRIVATE "-F/System/Library/PrivateFrameworks"
     )
 elseif(WIN32)
     target_link_libraries(libfastfetch
diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c
index fb5db626..1da27d10 100644
--- a/src/common/processing_linux.c
+++ b/src/common/processing_linux.c
@@ -19,7 +19,10 @@
     #include <sys/sysctl.h>
 #endif
 #if defined(__APPLE__)
-    #include <libproc.h>
+    #include <AvailabilityMacros.h>
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
+        #include <libproc.h>
+    #endif
 #elif defined(__sun)
     #include <procfs.h>
 #elif defined(__OpenBSD__)
@@ -193,6 +196,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
             ffStrbufSetS(exe, arg0);
         }
     }
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // No proc_pidpath on 10.4
     else
     {
         ffStrbufEnsureFixedLengthFree(exe, PATH_MAX);
@@ -205,6 +209,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
         }
     }
 
+    #endif
     #elif defined(__FreeBSD__) || defined(__NetBSD__)
 
     size_t size = ARG_MAX;
diff --git a/src/detection/bluetooth/bluetooth_apple.m b/src/detection/bluetooth/bluetooth_apple.m
index abd31a0c..d5e83094 100644
--- a/src/detection/bluetooth/bluetooth_apple.m
+++ b/src/detection/bluetooth/bluetooth_apple.m
@@ -2,8 +2,19 @@
 
 #import <IOBluetooth/IOBluetooth.h>
 
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
+
 const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
 {
+    POOLSTART
     NSArray<IOBluetoothDevice*>* ioDevices = IOBluetoothDevice.pairedDevices;
     if(!ioDevices)
         return "IOBluetoothDevice.pairedDevices failed";
@@ -87,6 +98,6 @@ const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
             ffStrbufTrimRight(&device->type, ',');
         }
     }
-
+    POOLEND
     return NULL;
 }
diff --git a/src/detection/camera/camera_apple.m b/src/detection/camera/camera_apple.m
index ab15fb99..d30c4259 100644
--- a/src/detection/camera/camera_apple.m
+++ b/src/detection/camera/camera_apple.m
@@ -1,7 +1,11 @@
 #include "camera.h"
 #include "common/io/io.h"
 
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 #import <AVFoundation/AVCaptureDevice.h>
+#endif
 
 // warning: 'AVCaptureDeviceTypeExternalUnknown' is deprecated
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
diff --git a/src/detection/cursor/cursor_apple.m b/src/detection/cursor/cursor_apple.m
index 29187e11..c0cbbd1f 100644
--- a/src/detection/cursor/cursor_apple.m
+++ b/src/detection/cursor/cursor_apple.m
@@ -2,12 +2,22 @@
 
 #import <Foundation/Foundation.h>
 
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
+
 static void appendColor(FFstrbuf* str, NSDictionary* color)
 {
-    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);
+    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);
 
     if (r == 255 && g == 255 && b == 255 && a == 255)
         ffStrbufAppendS(str, "White");
@@ -19,34 +29,28 @@ static void appendColor(FFstrbuf* str, NSDictionary* color)
 
 void ffDetectCursor(FFCursorResult* result)
 {
-    NSError* error;
-    NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/com.apple.universalaccess.plist", instance.state.platform.homeDir.chars];
-    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
-                                       error:&error];
-    if(error)
-    {
-        ffStrbufAppendS(&result->error, error.localizedDescription.UTF8String);
-        return;
-    }
+    POOLSTART
+    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.apple.universalaccess.plist"]];
 
     NSDictionary* color;
 
     ffStrbufAppendS(&result->theme, "Fill - ");
-    if ((color = dict[@"cursorFill"]))
+    if ((color = [dict valueForKey:@"cursorFill"]))
         appendColor(&result->theme, color);
     else
         ffStrbufAppendS(&result->theme, "Black");
 
     ffStrbufAppendS(&result->theme, ", Outline - ");
 
-    if ((color = dict[@"cursorOutline"]))
+    if ((color = [dict valueForKey:@"cursorOutline"]))
         appendColor(&result->theme, color);
     else
         ffStrbufAppendS(&result->theme, "White");
 
-    NSNumber* mouseDriverCursorSize = dict[@"mouseDriverCursorSize"];
+    NSNumber* mouseDriverCursorSize = [dict valueForKey:@"mouseDriverCursorSize"];
     if (mouseDriverCursorSize)
         ffStrbufAppendF(&result->size, "%d", (int) (mouseDriverCursorSize.doubleValue * 32));
     else
         ffStrbufAppendS(&result->size, "32");
+    POOLEND
 }
diff --git a/src/detection/displayserver/displayserver.c b/src/detection/displayserver/displayserver.c
index c2ba3e59..74038c7d 100644
--- a/src/detection/displayserver/displayserver.c
+++ b/src/detection/displayserver/displayserver.c
@@ -1,5 +1,27 @@
 #include "displayserver.h"
 
+#ifdef CG_LEGACY_API
+
+uint32_t ffdsParseRefreshRate(int32_t refreshRate)
+{
+    if(refreshRate <= 0)
+        return 0;
+
+    int remainder = refreshRate % 5;
+    if(remainder >= 3)
+        refreshRate += (5 - remainder);
+    else
+        refreshRate -= remainder;
+
+    // All other typicall refresh rates are dividable by 5
+    if(refreshRate == 145)
+        refreshRate = 144;
+
+    return (uint32_t) refreshRate;
+}
+
+#endif
+
 FFDisplayResult* ffdsAppendDisplay(
     FFDisplayServerResult* result,
     uint32_t width,
diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h
index d1d21839..c2f6fffd 100644
--- a/src/detection/displayserver/displayserver.h
+++ b/src/detection/displayserver/displayserver.h
@@ -2,6 +2,13 @@
 
 #include "fastfetch.h"
 
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 || defined(__ppc__)
+#define CG_LEGACY_API
+#endif
+#endif
+
 #define FF_DE_PRETTY_PLASMA "KDE Plasma"
 #define FF_DE_PRETTY_GNOME "GNOME"
 #define FF_DE_PRETTY_GNOME_CLASSIC "GNOME Classic"
@@ -90,6 +97,10 @@ typedef struct FFDisplayServerResult
 
 const FFDisplayServerResult* ffConnectDisplayServer();
 
+#ifdef CG_LEGACY_API
+uint32_t ffdsParseRefreshRate(int32_t refreshRate);
+#endif
+
 FFDisplayResult* ffdsAppendDisplay(
     FFDisplayServerResult* result,
     uint32_t width,
diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c
index d5158492..1f9ecfd7 100644
--- a/src/detection/displayserver/displayserver_apple.c
+++ b/src/detection/displayserver/displayserver_apple.c
@@ -6,6 +6,35 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+
+#ifdef CG_LEGACY_API
+
+#include "common/sysctl.h"
+#include <ApplicationServices/ApplicationServices.h>
+
+typedef union
+{
+    uint8_t rawData[0xDC];
+    struct
+    {
+        uint32_t mode;
+        uint32_t flags;     // 0x4
+        uint32_t width;     // 0x8
+        uint32_t height;    // 0xC
+        uint32_t depth;     // 0x10
+        uint32_t dc2[42];
+        uint16_t dc3;
+        uint16_t freq;      // 0xBC
+        uint32_t dc4[4];
+        float density;      // 0xD0
+    } derived;
+} modes_D4;
+
+void CGSGetCurrentDisplayMode(CGDirectDisplayID display, int* modeNum);
+void CGSGetDisplayModeDescriptionOfLength(CGDirectDisplayID display, int idx, modes_D4* mode, int length);
+
+#endif
+
 #include <CoreGraphics/CGDirectDisplay.h>
 #include <CoreVideo/CVDisplayLink.h>
 
@@ -27,11 +56,22 @@ static void detectDisplays(FFDisplayServerResult* ds)
     FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
     for(uint32_t i = 0; i < screenCount; i++)
     {
+#ifdef CG_LEGACY_API
+        int modeID;
+        CGSGetCurrentDisplayMode(screens[i], &modeID);
+        modes_D4 mode;
+        CGSGetDisplayModeDescriptionOfLength(screens[i], modeID, &mode, 0xD4);
+#endif
         CGDirectDisplayID screen = screens[i];
+#ifndef CG_LEGACY_API
         CGDisplayModeRef mode = CGDisplayCopyDisplayMode(screen);
+
         if(mode)
+#endif
         {
-            //https://github.com/glfw/glfw/commit/aab08712dd8142b642e2042e7b7ba563acd07a45
+#ifdef CG_LEGACY_API
+            double refreshRate = ffdsParseRefreshRate(mode.derived.freq);
+#else
             double refreshRate = CGDisplayModeGetRefreshRate(mode);
 
             if (refreshRate == 0)
@@ -45,7 +85,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
                     CVDisplayLinkRelease(link);
                 }
             }
-
+#endif
             ffStrbufClear(&buffer);
             CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = NULL;
             #ifdef MAC_OS_X_VERSION_10_15
@@ -83,11 +123,21 @@ static void detectDisplays(FFDisplayServerResult* ds)
             }
 
             FFDisplayResult* display = ffdsAppendDisplay(ds,
+#ifdef CG_LEGACY_API
+                mode.derived.width,
+                mode.derived.height,
+#else
                 (uint32_t)CGDisplayModeGetPixelWidth(mode),
                 (uint32_t)CGDisplayModeGetPixelHeight(mode),
+#endif
                 refreshRate,
+#if MAC_OS_X_VERSION_MIN_REQUIRED > 1070
                 (uint32_t)CGDisplayModeGetWidth(mode),
                 (uint32_t)CGDisplayModeGetHeight(mode),
+#else
+                0,
+                0,
+#endif
                 (uint32_t)CGDisplayRotation(screen),
                 &buffer,
                 CGDisplayIsBuiltin(screen) ? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL,
@@ -99,6 +149,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
             );
             if (display)
             {
+#ifndef CG_LEGACY_API
                 // https://stackoverflow.com/a/33519316/9976392
                 // Also shitty, but better than parsing `CFCopyDescription(mode)`
                 CFDictionaryRef dict = (CFDictionaryRef) *((int64_t *)mode + 2);
@@ -125,7 +176,7 @@ static void detectDisplays(FFDisplayServerResult* ds)
                         display->hdrStatus = FF_DISPLAY_HDR_STATUS_UNSUPPORTED;
                 }
                 #endif
-
+#endif
                 display->serial = CGDisplaySerialNumber(screen);
                 int value;
                 if (ffCfDictGetInt(displayInfo, CFSTR(kDisplayYearOfManufacture), &value) == NULL)
@@ -133,7 +184,9 @@ static void detectDisplays(FFDisplayServerResult* ds)
                 if (ffCfDictGetInt(displayInfo, CFSTR(kDisplayWeekOfManufacture), &value) == NULL)
                     display->manufactureWeek = (uint16_t) value;
             }
+#ifndef CG_LEGACY_API
             CGDisplayModeRelease(mode);
+#endif
         }
         CGDisplayRelease(screen);
     }
@@ -142,7 +195,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
 void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
 {
     {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
         FF_CFTYPE_AUTO_RELEASE CFMachPortRef port = CGWindowServerCreateServerPort();
+#else
+        FF_CFTYPE_AUTO_RELEASE CFMachPortRef port = CGWindowServerCFMachPort();
+#endif
         if (port)
         {
             ffStrbufSetStatic(&ds->wmProcessName, "WindowServer");
diff --git a/src/detection/font/font_apple.m b/src/detection/font/font_apple.m
index 683acad0..a2c9fb74 100644
--- a/src/detection/font/font_apple.m
+++ b/src/detection/font/font_apple.m
@@ -4,6 +4,16 @@
 
 #import <AppKit/NSFont.h>
 
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
+
 static void generateString(FFFontResult* font)
 {
     if(font->fonts[0].length > 0)
@@ -23,6 +33,7 @@ static void generateString(FFFontResult* font)
 
 const char* ffDetectFontImpl(FFFontResult* result)
 {
+    POOLSTART
     ffStrbufAppendS(&result->fonts[0], [NSFont systemFontOfSize:12].familyName.UTF8String);
     ffStrbufAppendS(&result->fonts[1], [NSFont userFontOfSize:12].familyName.UTF8String);
     #ifdef MAC_OS_X_VERSION_10_15
@@ -32,6 +43,6 @@ const char* ffDetectFontImpl(FFFontResult* result)
     #endif
     ffStrbufAppendS(&result->fonts[3], [NSFont userFixedPitchFontOfSize:12].familyName.UTF8String);
     generateString(result);
-
+    POOLEND
     return NULL;
 }
diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c
index efc15ab5..10fd867c 100644
--- a/src/detection/host/host_apple.c
+++ b/src/detection/host/host_apple.c
@@ -4,6 +4,7 @@
 #include "util/stringUtils.h"
 
 #include <IOKit/IOKitLib.h>
+#include <AvailabilityMacros.h>
 
 static const char* getProductNameWithHwModel(const FFstrbuf* hwModel)
 {
@@ -238,6 +239,7 @@ const char* getProductNameWithIokit(FFstrbuf* result)
 
 const char* getOthersByIokit(FFHostResult* host)
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice"));
     if (!registryEntry)
         return "IOServiceGetMatchingService() failed";
@@ -253,7 +255,7 @@ const char* getOthersByIokit(FFHostResult* host)
     FF_CFTYPE_AUTO_RELEASE CFStringRef manufacturer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
     if (manufacturer)
         ffCfStrGetString(manufacturer, &host->vendor);
-
+#endif
     return NULL;
 }
 
diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c
index cdfdee12..23ce20dc 100644
--- a/src/detection/memory/memory_apple.c
+++ b/src/detection/memory/memory_apple.c
@@ -28,7 +28,9 @@ const char* ffDetectMemory(FFMemoryResult* ram)
     ram->bytesUsed = ((uint64_t)
         + vmstat.active_count
         + vmstat.inactive_count
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
         + vmstat.speculative_count
+#endif
         + vmstat.wire_count
 #if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
         + vmstat.compressor_page_count
diff --git a/src/detection/os/os_apple.m b/src/detection/os/os_apple.m
index b86202b1..803bed1c 100644
--- a/src/detection/os/os_apple.m
+++ b/src/detection/os/os_apple.m
@@ -6,25 +6,33 @@
 
 #include <stdlib.h>
 #include <string.h>
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
 
 static void parseSystemVersion(FFOSResult* os)
 {
-    NSError* error;
-    NSString* fileName = @"file:///System/Library/CoreServices/SystemVersion.plist";
-    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
-                                       error:&error];
-    if(error)
-        return;
+    POOLSTART
+    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:
+        @"/System/Library/CoreServices/SystemVersion.plist"];
 
     NSString* value;
 
-    if((value = dict[@"ProductName"]))
-        ffStrbufInitS(&os->name, value.UTF8String);
-    if((value = dict[@"ProductUserVisibleVersion"]))
-        ffStrbufInitS(&os->version, value.UTF8String);
-    if((value = dict[@"ProductBuildVersion"]))
-        ffStrbufInitS(&os->buildID, value.UTF8String);
+    if ((value = [dict objectForKey:@"ProductName"]))
+        ffStrbufInitS(&os->name, [value UTF8String]);
+    if ((value = [dict objectForKey:@"ProductUserVisibleVersion"]))
+        ffStrbufInitS(&os->version, [value UTF8String]);
+    if ((value = [dict objectForKey:@"ProductBuildVersion"]))
+        ffStrbufInitS(&os->buildID, [value UTF8String]);
+    POOLEND
 }
 
 static bool detectOSCodeName(FFOSResult* os)
diff --git a/src/detection/physicalmemory/physicalmemory_apple.m b/src/detection/physicalmemory/physicalmemory_apple.m
index 243b35ac..5cfd0ba9 100644
--- a/src/detection/physicalmemory/physicalmemory_apple.m
+++ b/src/detection/physicalmemory/physicalmemory_apple.m
@@ -3,7 +3,16 @@
 #include "util/smbiosHelper.h"
 #include "util/stringUtils.h"
 
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
 
 static void appendDevice(
     FFlist* result,
@@ -11,7 +20,7 @@ static void appendDevice(
     NSString* vendor,
     NSString* size,
 
-    // Intel only
+    // Intel and PowerPC
     NSString* locator,
     NSString* serial,
     NSString* partNumber,
@@ -66,6 +75,7 @@ static void appendDevice(
 
 const char* ffDetectPhysicalMemory(FFlist* result)
 {
+    POOLSTART
     FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
     if (ffProcessAppendStdOut(&buffer, (char* const[]) {
         "system_profiler",
@@ -77,31 +87,37 @@ const char* ffDetectPhysicalMemory(FFlist* result)
     }) != NULL)
         return "Starting `system_profiler SPMemoryDataType -xml -detailLevel full` failed";
 
-    NSArray* arr = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytes:buffer.chars length:buffer.length]
-                    options:NSPropertyListImmutable
-                    format:nil
-                    error:nil];
-    if (!arr || !arr.count)
+    NSString* error;
+    NSData* plistData = [NSData dataWithBytes:buffer.chars length:buffer.length];
+    NSPropertyListFormat format;
+    NSArray* arr = [NSPropertyListSerialization propertyListFromData:plistData
+                    mutabilityOption:NSPropertyListImmutable
+                    format:&format
+                    errorDescription:&error];
+    if (!arr) {
         return "system_profiler SPMemoryDataType returned an empty array";
+        [error release];
+    }
 
-    for (NSDictionary* data in arr[0][@"_items"])
+    for (NSDictionary* data in [[arr objectAtIndex:0] objectForKey:@"_items"])
     {
-        if (data[@"_items"])
+        if ([data objectForKey:@"_items"])
         {
-            // for Intel
-            for (NSDictionary* item in data[@"_items"])
+            // for Intel and PowerPC
+            for (NSDictionary* item in [data objectForKey:@"_items"])
             {
                 appendDevice(result,
-                    item[@"dimm_type"],
-                    item[@"dimm_manufacturer"],
-                    item[@"dimm_size"],
-                    item[@"_name"],
-                    item[@"dimm_serial_number"],
-                    item[@"dimm_part_number"],
-                    item[@"dimm_speed"],
-                    !![data[@"global_ecc_state"] isEqualToString:@"ecc_enabled"]);
+                    [item valueForKey:@"dimm_type"],
+                    [item valueForKey:@"dimm_manufacturer"],
+                    [item valueForKey:@"dimm_size"],
+                    [item valueForKey:@"_name"],
+                    [item valueForKey:@"dimm_serial_number"],
+                    [item valueForKey:@"dimm_part_number"],
+                    [item valueForKey:@"dimm_speed"],
+                    !![[data objectForKey:@"global_ecc_state"] isEqualToString:@"ecc_enabled"]);
             }
         }
+#ifdef __arm64__
         else
         {
             // for Apple Silicon
@@ -115,7 +131,8 @@ const char* ffDetectPhysicalMemory(FFlist* result)
                 nil,
                 false);
         }
+#endif
     }
-
+    POOLEND
     return NULL;
 }
diff --git a/src/detection/terminalfont/terminalfont_apple.m b/src/detection/terminalfont/terminalfont_apple.m
index 90fed7fd..b3f50ffa 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";
 
diff --git a/src/detection/wallpaper/wallpaper_apple.m b/src/detection/wallpaper/wallpaper_apple.m
index 6780828d..d04dd772 100644
--- a/src/detection/wallpaper/wallpaper_apple.m
+++ b/src/detection/wallpaper/wallpaper_apple.m
@@ -2,10 +2,14 @@
 #include "common/settings.h"
 #include "util/apple/osascript.h"
 
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
 
 const char* ffDetectWallpaper(FFstrbuf* result)
 {
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED > 130000
+
     {
         // For Sonoma
         // https://github.com/JohnCoates/Aerial/issues/1332
@@ -18,16 +22,16 @@ const char* ffDetectWallpaper(FFstrbuf* result)
             NSArray* choices = [dict valueForKeyPath:@"SystemDefault.Desktop.Content.Choices"];
             if (choices.count > 0)
             {
-                NSDictionary* choice = choices[0];
-                NSArray* files = choice[@"Files"];
+                NSDictionary* choice = [choices objectAtIndex:0];
+                NSArray* files = [choice valueForKey:@"Files"];
                 if (files.count > 0)
                 {
-                    NSString* file = files[0][@"relative"];
+                    NSString* file = [[files objectAtIndex: 0] valueForKey: @"relative"];
                     ffStrbufAppendS(result, [NSURL URLWithString:file].path.UTF8String);
                 }
                 else
                 {
-                    NSString* provider = choice[@"Provider"];
+                    NSString* provider = [choice valueForKey:@"Provider"];
                     NSString* builtinPrefix = @"com.apple.wallpaper.choice.";
                     if ([provider hasPrefix:builtinPrefix])
                         provider = [provider substringFromIndex:builtinPrefix.length];
@@ -44,6 +48,8 @@ const char* ffDetectWallpaper(FFstrbuf* result)
         }
     }
 
+#endif
+
     #ifdef FF_HAVE_SQLITE3
 
     {
diff --git a/src/detection/wmtheme/wmtheme_apple.m b/src/detection/wmtheme/wmtheme_apple.m
index 8c43877b..c3fc8bb1 100644
--- a/src/detection/wmtheme/wmtheme_apple.m
+++ b/src/detection/wmtheme/wmtheme_apple.m
@@ -1,21 +1,24 @@
 #include "fastfetch.h"
 #include "wmtheme.h"
 
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
 
 bool ffDetectWmTheme(FFstrbuf* themeOrError)
 {
-    NSError* error;
-    NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/.GlobalPreferences.plist", instance.state.platform.homeDir.chars];
-    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
-                                       error:&error];
-    if(error)
-    {
-        ffStrbufAppendS(themeOrError, error.localizedDescription.UTF8String);
-        return false;
-    }
+    POOLSTART
+    NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/.GlobalPreferences.plist"]];
 
-    NSNumber* wmThemeColor = dict[@"AppleAccentColor"];
+    NSNumber* wmThemeColor = [dict valueForKey:@"AppleAccentColor"];
     if(!wmThemeColor)
         ffStrbufAppendS(themeOrError, "Multicolor");
     else
@@ -34,7 +37,8 @@ bool ffDetectWmTheme(FFstrbuf* themeOrError)
         }
     }
 
-    NSString* wmTheme = dict[@"AppleInterfaceStyle"];
+    NSString* wmTheme = [dict valueForKey:@"AppleInterfaceStyle"];
     ffStrbufAppendF(themeOrError, " (%s)", wmTheme ? wmTheme.UTF8String : "Light");
+    POOLEND
     return true;
 }
diff --git a/src/util/apple/osascript.h b/src/util/apple/osascript.h
index 164d8d70..1255ac30 100644
--- a/src/util/apple/osascript.h
+++ b/src/util/apple/osascript.h
@@ -3,3 +3,13 @@
 #include "fastfetch.h"
 
 bool ffOsascript(const char* input, FFstrbuf* result);
+
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
diff --git a/src/util/apple/osascript.m b/src/util/apple/osascript.m
index 8b01ba06..ebe9ae8e 100644
--- a/src/util/apple/osascript.m
+++ b/src/util/apple/osascript.m
@@ -1,17 +1,19 @@
 #include "osascript.h"
 
-#import <Foundation/Foundation.h>
-#import <AppKit/AppKit.h>
-#import <CoreData/CoreData.h>
+#include <Foundation/Foundation.h>
+#include <AppKit/AppKit.h>
+#include <CoreData/CoreData.h>
 
-bool ffOsascript(const char* input, FFstrbuf* result)
-{
-    NSAppleScript* script = [NSAppleScript.alloc initWithSource:@(input)];
+bool ffOsascript(const char* input, FFstrbuf* result) {
+    POOLSTART
+    NSString* appleScript = [NSString stringWithUTF8String: input];
+    NSAppleScript* script = [[NSAppleScript alloc] initWithSource:appleScript];
     NSDictionary* errInfo = nil;
     NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&errInfo];
     if (errInfo)
         return false;
 
-    ffStrbufSetS(result, descriptor.stringValue.UTF8String);
+    ffStrbufSetS(result, [[descriptor stringValue] cStringUsingEncoding:NSUTF8StringEncoding]);
+    POOLEND
     return true;
 }
diff --git a/src/util/kmod.c b/src/util/kmod.c
index 60d1889b..7dcaf0f8 100644
--- a/src/util/kmod.c
+++ b/src/util/kmod.c
@@ -35,7 +35,10 @@ bool ffKmodLoaded(const char* modName)
 #include "util/apple/cf_helpers.h"
 #include <IOKit/kext/KextManager.h>
 #include <CoreFoundation/CoreFoundation.h>
+#include <AvailabilityMacros.h>
 
+// KextManagerCopyLoadedKextInfo available in 10.7+
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 bool ffKmodLoaded(const char* modName)
 {
     FF_CFTYPE_AUTO_RELEASE CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, modName, kCFStringEncodingUTF8);
@@ -44,6 +47,12 @@ bool ffKmodLoaded(const char* modName)
     FF_CFTYPE_AUTO_RELEASE CFDictionaryRef kextInfo = KextManagerCopyLoadedKextInfo(identifiers, keys);
     return CFDictionaryContainsKey(kextInfo, name);
 }
+#else // MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+bool ffKmodLoaded(FF_MAYBE_UNUSED const char* modName)
+{
+    return true; // Don't generate kernel module related errors
+}
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED
 #else
 bool ffKmodLoaded(FF_MAYBE_UNUSED const char* modName)
 {
diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c
index b0d0ac1b..3672da3a 100644
--- a/src/util/platform/FFPlatform_unix.c
+++ b/src/util/platform/FFPlatform_unix.c
@@ -10,7 +10,10 @@
 #include <paths.h>
 
 #ifdef __APPLE__
+  #include <AvailabilityMacros.h>
+  #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     #include <libproc.h>
+  #endif
     #include <sys/sysctl.h>
 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
     #include <sys/sysctl.h>
@@ -22,7 +25,7 @@ static void getExePath(FFPlatform* platform)
     #ifdef __linux__
         ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
         exePath[exePathLen] = '\0';
-    #elif defined(__APPLE__)
+    #elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
         int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath));
     #elif defined(__FreeBSD__) || defined(__NetBSD__)
         size_t exePathLen = sizeof(exePath);
-- 
2.47.0

