Skip to content

Commit

Permalink
[CoreServices] Add support for Xcode 15. (#18919)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Sep 5, 2023
1 parent 1b81805 commit 138884a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 16 deletions.
78 changes: 78 additions & 0 deletions src/CoreServices/LaunchServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ public static class LaunchServices

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyDefaultApplicationURLForURL (IntPtr inUrl, LSRoles inRole, /*out*/ IntPtr outError);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static NSUrl? GetDefaultApplicationUrlForUrl (NSUrl url, LSRoles roles = LSRoles.All)
{
Expand All @@ -114,12 +120,18 @@ public static class LaunchServices

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyDefaultApplicationURLForContentType (IntPtr inContentType, LSRoles inRole, /*out*/ IntPtr outError);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static NSUrl? GetDefaultApplicationUrlForContentType (string contentType, LSRoles roles = LSRoles.All)
{
Expand All @@ -131,9 +143,21 @@ public static class LaunchServices
);
}

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyApplicationURLsForURL (IntPtr inUrl, LSRoles inRole);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static NSUrl [] GetApplicationUrlsForUrl (NSUrl url, LSRoles roles = LSRoles.All)
{
if (url is null)
Expand Down Expand Up @@ -172,12 +196,18 @@ public static bool CanUrlAcceptUrl (NSUrl itemUrl, NSUrl targetUrl,

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyApplicationURLsForBundleIdentifier (IntPtr inBundleIdentifier, /*out*/ IntPtr outError);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static NSUrl [] GetApplicationUrlsForBundleIdentifier (string bundleIdentifier)
{
Expand Down Expand Up @@ -234,9 +264,21 @@ public static LSResult Register (NSUrl url, bool update)

#region Working with Role Handlers

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyAllRoleHandlersForContentType (IntPtr inContentType, LSRoles inRole);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static string?[]? GetAllRoleHandlersForContentType (string contentType, LSRoles roles = LSRoles.All)
{
if (contentType is null)
Expand All @@ -247,9 +289,21 @@ public static LSResult Register (NSUrl url, bool update)
);
}

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern IntPtr LSCopyDefaultRoleHandlerForContentType (IntPtr inContentType, LSRoles inRole);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static string GetDefaultRoleHandlerForContentType (string contentType, LSRoles roles = LSRoles.All)
{
if (contentType is null)
Expand All @@ -260,10 +314,22 @@ public static string GetDefaultRoleHandlerForContentType (string contentType, LS
);
}

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern LSResult LSSetDefaultRoleHandlerForContentType (IntPtr inContentType,
LSRoles inRole, IntPtr inHandlerBundleID);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
// NOTE: intentionally swapped handlerBundleId and roles parameters for a nicer API
public static LSResult SetDefaultRoleHandlerForContentType (string contentType, string handlerBundleId,
LSRoles roles = LSRoles.All)
Expand Down Expand Up @@ -330,9 +396,21 @@ public static string GetDefaultHandlerForUrlScheme (string urlScheme)
);
}

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
[DllImport (Constants.CoreServicesLibrary)]
static extern LSResult LSSetDefaultHandlerForURLScheme (IntPtr inUrlScheme, IntPtr inHandlerBundleId);

#if NET
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos14.0")]
#else
[Deprecated (PlatformName.MacOSX, 14, 0)]
#endif
public static LSResult SetDefaultHandlerForUrlScheme (string urlScheme, string handlerBundleId)
{
if (urlScheme is null)
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions tests/xtro-sharpie/macOS-CoreServices.todo

This file was deleted.

5 comments on commit 138884a

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.