From bfb176f66291c26817a65181c6d31adfef0f43ee Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 1 Aug 2025 17:31:46 +0200 Subject: [PATCH 1/2] [MediaAccessibility] Update to Xcode 26 beta 1-5. --- src/MediaAccessibility/MediaAccessibility.cs | 118 ++++++++++++++++++ .../CaptionAppearanceTest.cs | 30 +++++ .../MacCatalyst-MediaAccessibility.todo | 5 - .../iOS-MediaAccessibility.todo | 5 - .../macOS-MediaAccessibility.todo | 5 - .../tvOS-MediaAccessibility.todo | 5 - 6 files changed, 148 insertions(+), 20 deletions(-) delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-MediaAccessibility.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/iOS-MediaAccessibility.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/macOS-MediaAccessibility.todo delete mode 100644 tests/xtro-sharpie/api-annotations-dotnet/tvOS-MediaAccessibility.todo diff --git a/src/MediaAccessibility/MediaAccessibility.cs b/src/MediaAccessibility/MediaAccessibility.cs index 054930908f62..cd1121873d59 100644 --- a/src/MediaAccessibility/MediaAccessibility.cs +++ b/src/MediaAccessibility/MediaAccessibility.cs @@ -361,6 +361,124 @@ public static bool IsCustomized (MACaptionAppearanceDomain domain) { return MACaptionAppearanceIsCustomized ((nint) (long) domain) != 0; } + + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [DllImport (Constants.MediaAccessibilityLibrary)] + static extern /* CFArrayRef CF_RETURNS_RETAINED */ IntPtr MACaptionAppearanceCopyProfileIDs (); + + /// Gets all the system and user-defined profile identifiers. + /// A string array of profile identifiers. + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + public static string[]? GetProfileIds () + { + var handle = MACaptionAppearanceCopyProfileIDs (); + var rv = CFArray.StringArrayFromHandle (handle, releaseHandle: true); + return (string[]?) (object?) rv; + } + + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [DllImport (Constants.MediaAccessibilityLibrary)] + static extern void MACaptionAppearanceSetActiveProfileID (IntPtr /* CFStringRef */ profileID); + + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [DllImport (Constants.MediaAccessibilityLibrary)] + static extern /* CFStringRef CF_RETURNS_RETAINED */ IntPtr MACaptionAppearanceCopyActiveProfileID (); + + /// Gets or sets the currently active system-wide caption-drawing profile by its identifier. + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + public static string? ActiveProfileId { + get { + return CFString.FromHandle (MACaptionAppearanceCopyActiveProfileID (), true); + } + set { + if (value is null) + ThrowHelper.ThrowArgumentNullException (nameof (value)); + + using var profileIdHandle = new TransientCFString (value); + MACaptionAppearanceSetActiveProfileID (profileIdHandle); + } + } + + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [DllImport (Constants.MediaAccessibilityLibrary)] + static extern /* CFStringRef CF_RETURNS_RETAINED */ IntPtr MACaptionAppearanceCopyProfileName (/* CFStringRef */ IntPtr profileId); + + /// Get the human-readable name for a given profile identifier. + /// The profile identifier whose human-readable name to return. + /// The human-readable name for the specified profile identifier. + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + public static string? GetProfileName (string profileId) + { + if (profileId is null) + ThrowHelper.ThrowArgumentNullException (nameof (profileId)); + + using var profileIdHandle = new TransientCFString (profileId); + return CFString.FromHandle (MACaptionAppearanceCopyProfileName (profileIdHandle), true); + } + + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [DllImport (Constants.MediaAccessibilityLibrary)] + unsafe static extern void MACaptionAppearanceExecuteBlockForProfileID (IntPtr /* CFStringRef */ profileId, BlockLiteral* aBlock); + + /// Execute a callback as if the specified profile was the currently active profile. + /// The identifier for the profile that will be active when the callback is executed. + /// The callback to call with the specified profile as the currently active profile. + /// This method can be used to get the fonts and colors for a profile without changing the currently selected profile. + [SupportedOSPlatform ("tvos26.0")] + [SupportedOSPlatform ("macos26.0")] + [SupportedOSPlatform ("ios26.0")] + [SupportedOSPlatform ("maccatalyst26.0")] + [BindingImpl (BindingImplOptions.Optimizable)] + public static void ExecuteCallbackForProfile (string profileId, Action callback) + { + if (profileId is null) + ThrowHelper.ThrowArgumentNullException (nameof (profileId)); + + if (callback is null) + ThrowHelper.ThrowArgumentNullException (nameof (callback)); + + using var profileIdHandle = new TransientCFString (profileId); + + unsafe { + delegate* unmanaged trampoline = &Callback; + using var block = new BlockLiteral (trampoline, callback, typeof (MACaptionAppearance), nameof (Callback)); + MACaptionAppearanceExecuteBlockForProfileID (profileIdHandle, &block); + } + } + + [UnmanagedCallersOnly] + static void Callback (IntPtr block) + { + var del = BlockLiteral.GetTarget (block); + if (del is null) + return; + + del (); + } } [SupportedOSPlatform ("ios")] diff --git a/tests/monotouch-test/MediaAccessibility/CaptionAppearanceTest.cs b/tests/monotouch-test/MediaAccessibility/CaptionAppearanceTest.cs index 3d6be5a9a74d..a13ad509de80 100644 --- a/tests/monotouch-test/MediaAccessibility/CaptionAppearanceTest.cs +++ b/tests/monotouch-test/MediaAccessibility/CaptionAppearanceTest.cs @@ -57,5 +57,35 @@ public void IsCustomized () Assert.That (MACaptionAppearance.IsCustomized (value), Is.EqualTo (true).Or.EqualTo (false), value.ToString ()); } } + + [Test] + public void TestProfiles () + { + TestRuntime.AssertXcodeVersion (26, 0); + + Assert.Multiple (() => { + var profiles = MACaptionAppearance.GetProfileIds (); + Assert.That (profiles, Is.Not.Empty, "Profiles"); + + Assert.That (MACaptionAppearance.ActiveProfileId, Is.Not.Null, "ActiveProfileId#1"); + var originalProfileId = MACaptionAppearance.ActiveProfileId; + try { + MACaptionAppearance.ActiveProfileId = profiles [0]; + Assert.That (MACaptionAppearance.ActiveProfileId, Is.EqualTo (profiles [0]), "ActiveProfileId#2"); + } finally { + MACaptionAppearance.ActiveProfileId = originalProfileId; + } + + foreach (var p in profiles) { + Assert.That (MACaptionAppearance.GetProfileName (p), Is.Not.Null.And.Not.Empty, $"ProfileName - {p}"); + } + + var calledCallback = false; + MACaptionAppearance.ExecuteCallbackForProfile (profiles [0], () => { + calledCallback = true; + }); + Assert.That (calledCallback, Is.True, "ExecuteCallbackForProfile"); + }); + } } } diff --git a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-MediaAccessibility.todo b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-MediaAccessibility.todo deleted file mode 100644 index d80bbc1b72bf..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-MediaAccessibility.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-pinvoke! MACaptionAppearanceCopyActiveProfileID is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileIDs is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileName is not bound -!missing-pinvoke! MACaptionAppearanceExecuteBlockForProfileID is not bound -!missing-pinvoke! MACaptionAppearanceSetActiveProfileID is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/iOS-MediaAccessibility.todo b/tests/xtro-sharpie/api-annotations-dotnet/iOS-MediaAccessibility.todo deleted file mode 100644 index d80bbc1b72bf..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/iOS-MediaAccessibility.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-pinvoke! MACaptionAppearanceCopyActiveProfileID is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileIDs is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileName is not bound -!missing-pinvoke! MACaptionAppearanceExecuteBlockForProfileID is not bound -!missing-pinvoke! MACaptionAppearanceSetActiveProfileID is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-MediaAccessibility.todo b/tests/xtro-sharpie/api-annotations-dotnet/macOS-MediaAccessibility.todo deleted file mode 100644 index d80bbc1b72bf..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-MediaAccessibility.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-pinvoke! MACaptionAppearanceCopyActiveProfileID is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileIDs is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileName is not bound -!missing-pinvoke! MACaptionAppearanceExecuteBlockForProfileID is not bound -!missing-pinvoke! MACaptionAppearanceSetActiveProfileID is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-MediaAccessibility.todo b/tests/xtro-sharpie/api-annotations-dotnet/tvOS-MediaAccessibility.todo deleted file mode 100644 index d80bbc1b72bf..000000000000 --- a/tests/xtro-sharpie/api-annotations-dotnet/tvOS-MediaAccessibility.todo +++ /dev/null @@ -1,5 +0,0 @@ -!missing-pinvoke! MACaptionAppearanceCopyActiveProfileID is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileIDs is not bound -!missing-pinvoke! MACaptionAppearanceCopyProfileName is not bound -!missing-pinvoke! MACaptionAppearanceExecuteBlockForProfileID is not bound -!missing-pinvoke! MACaptionAppearanceSetActiveProfileID is not bound From 6331dee7afe485ecd282e6a44122718ad80cc07e Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Tue, 19 Aug 2025 04:44:26 +0000 Subject: [PATCH 2/2] Auto-format source code --- src/MediaAccessibility/MediaAccessibility.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MediaAccessibility/MediaAccessibility.cs b/src/MediaAccessibility/MediaAccessibility.cs index cd1121873d59..449e99921397 100644 --- a/src/MediaAccessibility/MediaAccessibility.cs +++ b/src/MediaAccessibility/MediaAccessibility.cs @@ -375,11 +375,11 @@ public static bool IsCustomized (MACaptionAppearanceDomain domain) [SupportedOSPlatform ("macos26.0")] [SupportedOSPlatform ("ios26.0")] [SupportedOSPlatform ("maccatalyst26.0")] - public static string[]? GetProfileIds () + public static string []? GetProfileIds () { var handle = MACaptionAppearanceCopyProfileIDs (); var rv = CFArray.StringArrayFromHandle (handle, releaseHandle: true); - return (string[]?) (object?) rv; + return (string []?) (object?) rv; } [SupportedOSPlatform ("tvos26.0")]