Skip to content

Commit

Permalink
Fix compatibility with pre-10.10 OS X
Browse files Browse the repository at this point in the history
User-Agent change from 2c8dae7 broke Poedit on OS X older than
Yosemite, where it caused early abort, because [NSProcessInfo
operatingSystemVersion] wasn't available until 10.9.2 (and 10.10
officially).

Use the now-deprecated Gestalt() function on older systems.
  • Loading branch information
vslavik committed Oct 21, 2015
1 parent a370b74 commit fb2d65f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/http_client_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,24 @@ static inline json_dict make_json_dict(NSDictionary *d)
// to the server.
[m_native.operationQueue setMaxConcurrentOperationCount:NSIntegerMax];

NSOperatingSystemVersion osx = [[NSProcessInfo processInfo] operatingSystemVersion];
NSString *osx_str = (osx.patchVersion == 0)
? [NSString stringWithFormat:@"%d.%d", (int)osx.majorVersion, (int)osx.minorVersion]
: [NSString stringWithFormat:@"%d.%d.%d", (int)osx.majorVersion, (int)osx.minorVersion, (int)osx.patchVersion];
int majorVersion, minorVersion, patchVersion;
NSProcessInfo *process = [NSProcessInfo processInfo];
if ([process respondsToSelector:@selector(operatingSystemVersion)])
{
NSOperatingSystemVersion osx = [process operatingSystemVersion];
majorVersion = (int)osx.majorVersion;
minorVersion = (int)osx.minorVersion;
patchVersion = (int)osx.patchVersion;
}
else
{
Gestalt(gestaltSystemVersionMajor, &majorVersion);
Gestalt(gestaltSystemVersionMinor, &minorVersion);
Gestalt(gestaltSystemVersionBugFix, &patchVersion);
}
NSString *osx_str = (patchVersion == 0)
? [NSString stringWithFormat:@"%d.%d", majorVersion, minorVersion]
: [NSString stringWithFormat:@"%d.%d.%d", majorVersion, minorVersion, patchVersion];
[m_native setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"Poedit/%s (Mac OS X %@)", POEDIT_VERSION, osx_str]];
}

Expand Down

0 comments on commit fb2d65f

Please sign in to comment.