Skip to content

Commit 2f6613c

Browse files
Merge pull request #274 from CarterLi/master
macOS: respect CMAKE_INSTALL_SYSCONFDIR; use Cocoa API to parse plist files
2 parents b0ad129 + 145e09d commit 2f6613c

File tree

15 files changed

+169
-318
lines changed

15 files changed

+169
-318
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
uses: actions/checkout@v3
6565

6666
- name: install required packages
67-
run: brew install vulkan-loader libplist
67+
run: brew install vulkan-loader molten-vk
6868

6969
- name: Initialize CodeQL
7070
uses: github/codeql-action/init@v2

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR BSD" OFF)
4646
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR BSD" OFF)
4747
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD" OFF)
4848
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD" OFF)
49-
cmake_dependent_option(ENABLE_LIBPLIST "Enable libplist" ON "APPLE" OFF)
5049
cmake_dependent_option(ENABLE_LIBCJSON "Enable libcjson" ON "LINUX" OFF)
5150
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
5251

@@ -123,6 +122,10 @@ if(NOT TARGET_DIR_HOME)
123122
endif()
124123
endif()
125124

125+
if(NOT TARGET_DIR_ETC)
126+
set(TARGET_DIR_ETC "${CMAKE_INSTALL_SYSCONFDIR}")
127+
endif()
128+
126129
#################
127130
# Tweak version #
128131
#################
@@ -294,17 +297,17 @@ if(APPLE)
294297
src/util/apple/cf_helpers.c
295298
src/util/apple/osascript.m
296299
src/detection/host/host_apple.c
297-
src/detection/os/os_apple.c
300+
src/detection/os/os_apple.m
298301
src/detection/cpu/cpu_apple.c
299302
src/detection/gpu/gpu_apple.c
300303
src/detection/battery/battery_apple.c
301304
src/detection/poweradapter/poweradapter_apple.c
302305
src/detection/memory/memory_apple.c
303306
src/detection/displayserver/displayserver_apple.c
304-
src/detection/terminalfont/terminalfont_apple.c
307+
src/detection/terminalfont/terminalfont_apple.m
305308
src/detection/media/media_apple.m
306309
src/detection/disk/disk_apple.m
307-
src/detection/wmtheme/wmtheme_apple.c
310+
src/detection/wmtheme/wmtheme_apple.m
308311
src/detection/temps/temps_apple.c
309312
src/detection/font/font_apple.m
310313
)
@@ -392,7 +395,6 @@ ff_lib_enable(EGL egl)
392395
ff_lib_enable(GLX glx)
393396
ff_lib_enable(OSMESA osmesa)
394397
ff_lib_enable(OPENCL OpenCL)
395-
ff_lib_enable(LIBPLIST libplist-2.0)
396398
ff_lib_enable(LIBCJSON libcjson)
397399
ff_lib_enable(FREETYPE freetype2)
398400

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ The following libraries are used if present at runtime:
4444
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
4545
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for pkg & rpm package count.
4646
* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE.
47-
* [`libplist`](https://github.com/libimobiledevice/libplist): Binary `plist` file parser ( macOS ). Needed for iTerm2 Terminal font and WM Theme.
4847
* [`libcJSON`](https://github.com/DaveGamble/cJSON): Needed for Windows Terminal font ( WSL ).
4948
* [`freetype`](https://www.freetype.org/): Needed for Termux font detection ( Android ).
5049

src/common/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ static void defaultConfig(FFinstance* instance)
219219
ffStrbufInitA(&instance->config.libGLX, 0);
220220
ffStrbufInitA(&instance->config.libOSMesa, 0);
221221
ffStrbufInitA(&instance->config.libOpenCL, 0);
222-
ffStrbufInitA(&instance->config.libplist, 0);
223222
ffStrbufInitA(&instance->config.libcJSON, 0);
224223
ffStrbufInitA(&instance->config.libfreetype, 0);
225224

@@ -482,9 +481,6 @@ void ffListFeatures()
482481
#ifdef FF_HAVE_OPENCL
483482
"opencl\n"
484483
#endif
485-
#ifdef FF_HAVE_LIBPLIST
486-
"libplist\n"
487-
#endif
488484
#ifdef FF_HAVE_LIBCJSON
489485
"libcjson\n"
490486
#endif

src/data/config_user.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,5 @@
347347
#--lib-glx /usr/lib/libGLX.so
348348
#--lib-osmesa /usr/lib/libOSMesa.so
349349
#--lib-opencl /usr/lib/libOpenCL.so
350-
#--lib-plist /usr/local/bin/libplist-2.0.dylib
351350
#--lib-cjson /usr/lib/libcjson.so
352351
#--lib-freetype /data/data/com.termux/files/usr/lib

src/data/help.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Library options: Set the path of a library to load
8484
--lib-glx <path>
8585
--lib-osmesa <path>
8686
--lib-opencl <path>
87-
--lib-plist <path>
8887
--lib-cjson <path>
8988

9089
Module specific options:

src/detection/os/os_apple.c renamed to src/detection/os/os_apple.m

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,27 @@
11
#include "os.h"
2-
#include "common/properties.h"
32
#include "common/sysctl.h"
43

54
#include <stdlib.h>
65
#include <string.h>
7-
8-
typedef enum PListKey
9-
{
10-
PLIST_KEY_NAME,
11-
PLIST_KEY_VERSION,
12-
PLIST_KEY_BUILD,
13-
PLIST_KEY_OTHER
14-
} PListKey;
6+
#import <Foundation/Foundation.h>
157

168
static void parseSystemVersion(FFOSResult* os)
179
{
18-
FILE* plist = fopen("/System/Library/CoreServices/SystemVersion.plist", "r");
19-
if(plist == NULL)
20-
return;
21-
22-
char* line = NULL;
23-
size_t len = 0;
24-
PListKey key = PLIST_KEY_OTHER;
25-
26-
FFstrbuf keyBuffer;
27-
ffStrbufInit(&keyBuffer);
28-
29-
while(getline(&line, &len, plist) != EOF)
30-
{
31-
if(ffParsePropLine(line, "<key>", &keyBuffer))
32-
{
33-
if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductName") == 0)
34-
key = PLIST_KEY_NAME;
35-
else if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductUserVisibleVersion") == 0)
36-
key = PLIST_KEY_VERSION;
37-
else if(ffStrbufIgnCaseCompS(&keyBuffer, "ProductBuildVersion") == 0)
38-
key = PLIST_KEY_BUILD;
39-
else
40-
key = PLIST_KEY_OTHER;
41-
42-
ffStrbufClear(&keyBuffer);
43-
continue;
44-
}
45-
46-
if(key == PLIST_KEY_NAME)
47-
ffParsePropLine(line, "<string>", &os->name);
48-
else if(key == PLIST_KEY_VERSION)
49-
ffParsePropLine(line, "<string>", &os->version);
50-
else if(key == PLIST_KEY_BUILD)
51-
ffParsePropLine(line, "<string>", &os->buildID);
52-
}
53-
54-
ffStrbufDestroy(&keyBuffer);
10+
NSError* error;
11+
NSString* fileName = @"file:///System/Library/CoreServices/SystemVersion.plist";
12+
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
13+
error:&error];
14+
if(error)
15+
return;
5516

56-
if(line != NULL)
57-
free(line);
17+
NSString* value;
5818

59-
fclose(plist);
19+
if((value = [dict valueForKey:@"ProductName"]))
20+
ffStrbufInitS(&os->name, value.UTF8String);
21+
if((value = [dict valueForKey:@"ProductUserVisibleVersion"]))
22+
ffStrbufInitS(&os->version, value.UTF8String);
23+
if((value = [dict valueForKey:@"ProductBuildVersion"]))
24+
ffStrbufInitS(&os->buildID, value.UTF8String);
6025
}
6126

6227
void parseOSXSoftwareLicense(FFOSResult* os)

src/detection/terminalfont/terminalfont_apple.c

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "terminalfont.h"
2+
#include "common/font.h"
3+
#include "detection/terminalshell.h"
4+
#include "util/apple/osascript.h"
5+
6+
#include <stdlib.h>
7+
#include <string.h>
8+
#import <Foundation/Foundation.h>
9+
10+
static void detectIterm2(const FFinstance* instance, FFTerminalFontResult* terminalFont)
11+
{
12+
const char* profile = getenv("ITERM_PROFILE");
13+
if (profile == NULL)
14+
{
15+
ffStrbufAppendS(&terminalFont->error, "environment variable ITERM_PROFILE not set");
16+
return;
17+
}
18+
19+
NSError* error;
20+
NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/com.googlecode.iterm2.plist", instance->state.passwd->pw_dir];
21+
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
22+
error:&error];
23+
if(error)
24+
{
25+
ffStrbufAppendS(&terminalFont->error, [error localizedDescription].UTF8String);
26+
return;
27+
}
28+
29+
for(NSDictionary* bookmark in [dict valueForKey:@"New Bookmarks"])
30+
{
31+
if(![[bookmark valueForKey:@"Name"] isEqualToString:@(profile)])
32+
continue;
33+
34+
NSString* normalFont = [bookmark valueForKey:@"Normal Font"];
35+
if(!normalFont)
36+
{
37+
ffStrbufAppendF(&terminalFont->error, "`Normal Font` key in profile `%s` doesn't exist", profile);
38+
return;
39+
}
40+
ffFontInitWithSpace(&terminalFont->font, normalFont.UTF8String);
41+
return;
42+
}
43+
44+
ffStrbufAppendF(&terminalFont->error, "find profile `%s` bookmark failed", profile);
45+
}
46+
47+
static void detectAppleTerminal(FFTerminalFontResult* terminalFont)
48+
{
49+
FFstrbuf fontName;
50+
ffStrbufInit(&fontName);
51+
ffOsascript("tell application \"Terminal\" to font name of window frontmost", &fontName);
52+
53+
if(fontName.length == 0)
54+
{
55+
ffStrbufAppendS(&terminalFont->error, "executing osascript failed");
56+
ffStrbufDestroy(&fontName);
57+
return;
58+
}
59+
60+
FFstrbuf fontSize;
61+
ffStrbufInit(&fontSize);
62+
ffOsascript("tell application \"Terminal\" to font size of window frontmost", &fontSize);
63+
64+
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
65+
66+
ffStrbufDestroy(&fontName);
67+
ffStrbufDestroy(&fontSize);
68+
}
69+
70+
void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
71+
{
72+
if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "iterm.app") == 0)
73+
detectIterm2(instance, terminalFont);
74+
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "Apple_Terminal") == 0)
75+
detectAppleTerminal(terminalFont);
76+
}

0 commit comments

Comments
 (0)