build: Xcode 11.3.1 compatibility (#6292)

This commit is contained in:
Cœur 2023-11-26 05:01:44 +01:00 committed by GitHub
parent a12ef941e7
commit 089a697809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -5,11 +5,14 @@
#import "DefaultAppHelper.h"
#import <AppKit/AppKit.h>
#ifdef __MAC_12_0
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
#endif
static NSString* const kMagnetURLScheme = @"magnet";
static NSString* const kTorrentFileType = @"org.bittorrent.torrent";
#ifdef __MAC_12_0
UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
{
static UTType* result = nil;
@ -21,6 +24,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
return result;
}
#endif
@interface DefaultAppHelper ()
@ -41,6 +45,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
- (BOOL)isDefaultForTorrentFiles
{
#ifdef __MAC_12_0
if (@available(macOS 12, *))
{
UTType* fileType = GetTorrentFileType();
@ -58,8 +63,9 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
}
}
else
#endif
{
NSString* bundleId = (__bridge NSString*)LSCopyDefaultRoleHandlerForContentType((__bridge CFStringRef)kTorrentFileType, kLSRolesViewer);
NSString* bundleId = (__bridge_transfer NSString*)LSCopyDefaultRoleHandlerForContentType((__bridge CFStringRef)kTorrentFileType, kLSRolesViewer);
if (!bundleId)
{
return NO;
@ -76,6 +82,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
- (void)setDefaultForTorrentFiles:(void (^_Nullable)())completionHandler
{
#ifdef __MAC_12_0
if (@available(macOS 12, *))
{
UTType* fileType = GetTorrentFileType();
@ -94,6 +101,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
}];
}
else
#endif
{
OSStatus const result = LSSetDefaultRoleHandlerForContentType(
(__bridge CFStringRef)kTorrentFileType,
@ -130,7 +138,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
}
else
{
NSString* bundleId = (__bridge NSString*)LSCopyDefaultHandlerForURLScheme((__bridge CFStringRef)kMagnetURLScheme);
NSString* bundleId = (__bridge_transfer NSString*)LSCopyDefaultHandlerForURLScheme((__bridge CFStringRef)kMagnetURLScheme);
if (!bundleId)
{
return NO;
@ -147,6 +155,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
- (void)setDefaultForMagnetURLs:(void (^_Nullable)())completionHandler
{
#ifdef __MAC_12_0
if (@available(macOS 12, *))
{
NSURL* appUrl = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:self.bundleIdentifier];
@ -165,6 +174,7 @@ UTType* GetTorrentFileType(void) API_AVAILABLE(macos(11.0))
}];
}
else
#endif
{
OSStatus const result = LSSetDefaultHandlerForURLScheme(
(__bridge CFStringRef)kMagnetURLScheme,