|
136 | 136 | return @"/Applications/Xcode.app/Contents/Developer/Library/PrivateFrameworks/SimulatorKit.framework/SimulatorKit"; |
137 | 137 | } |
138 | 138 |
|
| 139 | +static NSInteger DFXcodeMajorVersion(void) { |
| 140 | + NSString *developerPath = nil; |
| 141 | + const char *developerDir = getenv("DEVELOPER_DIR"); |
| 142 | + if (developerDir != NULL && developerDir[0] != '\0') { |
| 143 | + developerPath = [NSString stringWithUTF8String:developerDir]; |
| 144 | + } else { |
| 145 | + FILE *pipe = popen("/usr/bin/xcode-select -p 2>/dev/null", "r"); |
| 146 | + if (pipe != NULL) { |
| 147 | + char buffer[PATH_MAX] = {0}; |
| 148 | + if (fgets(buffer, sizeof(buffer), pipe) != NULL) { |
| 149 | + developerPath = [[NSString stringWithUTF8String:buffer] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
| 150 | + } |
| 151 | + pclose(pipe); |
| 152 | + } |
| 153 | + } |
| 154 | + if (developerPath.length == 0) { |
| 155 | + return 0; |
| 156 | + } |
| 157 | + |
| 158 | + NSString *contentsPath = developerPath; |
| 159 | + if ([contentsPath.lastPathComponent isEqualToString:@"Developer"]) { |
| 160 | + contentsPath = contentsPath.stringByDeletingLastPathComponent; |
| 161 | + } |
| 162 | + |
| 163 | + NSDictionary *versionInfo = [NSDictionary dictionaryWithContentsOfFile:[contentsPath stringByAppendingPathComponent:@"version.plist"]]; |
| 164 | + NSString *version = versionInfo[@"CFBundleShortVersionString"]; |
| 165 | + if (version.length == 0) { |
| 166 | + NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[contentsPath stringByAppendingPathComponent:@"Info.plist"]]; |
| 167 | + version = info[@"CFBundleShortVersionString"]; |
| 168 | + } |
| 169 | + return [[version componentsSeparatedByString:@"."].firstObject integerValue]; |
| 170 | +} |
| 171 | + |
139 | 172 | typedef struct { |
140 | 173 | __unsafe_unretained id unit; |
141 | 174 | double value; |
@@ -207,20 +240,7 @@ static BOOL DFShouldUseIndigoMouse9Path(void) { |
207 | 240 | return; |
208 | 241 | } |
209 | 242 |
|
210 | | - FILE *pipe = popen("/usr/bin/xcodebuild -version 2>/dev/null", "r"); |
211 | | - if (pipe == NULL) { |
212 | | - return; |
213 | | - } |
214 | | - char buffer[256] = {0}; |
215 | | - if (fgets(buffer, sizeof(buffer), pipe) != NULL) { |
216 | | - NSString *line = [[NSString stringWithUTF8String:buffer] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
217 | | - NSArray<NSString *> *parts = [line componentsSeparatedByString:@" "]; |
218 | | - if (parts.count >= 2 && [parts[0] isEqualToString:@"Xcode"]) { |
219 | | - NSInteger major = [[parts[1] componentsSeparatedByString:@"."].firstObject integerValue]; |
220 | | - enabled = major >= 26; |
221 | | - } |
222 | | - } |
223 | | - pclose(pipe); |
| 243 | + enabled = DFXcodeMajorVersion() >= 26; |
224 | 244 | }); |
225 | 245 | return enabled; |
226 | 246 | } |
|
0 commit comments