diff --git a/src/Uno.UWP/Devices/Midi/Internal/WasmMidiAccess.wasm.cs b/src/Uno.UWP/Devices/Midi/Internal/WasmMidiAccess.wasm.cs index 0f07586bf0be..943fc1faf7f3 100644 --- a/src/Uno.UWP/Devices/Midi/Internal/WasmMidiAccess.wasm.cs +++ b/src/Uno.UWP/Devices/Midi/Internal/WasmMidiAccess.wasm.cs @@ -2,16 +2,23 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; + +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.JavaScript; +#else using static Uno.Foundation.WebAssemblyRuntime; +#endif namespace Uno.Devices.Midi.Internal { /// /// Handles WASM MIDI access permission request /// - public static class WasmMidiAccess + public static partial class WasmMidiAccess { +#if !NET7_0_OR_GREATER private const string JsType = "Uno.Devices.Midi.Internal.WasmMidiAccess"; +#endif private static bool _webMidiAccessible; @@ -23,11 +30,26 @@ public static async Task RequestAsync() } var systemExclusiveRequested = WinRTFeatureConfiguration.Midi.RequestSystemExclusiveAccess; + +#if NET7_0_OR_GREATER + var result = await NativeMethods.RequestAsync(systemExclusiveRequested); +#else var serializedRequest = systemExclusiveRequested.ToString().ToLowerInvariant(); var command = $"{JsType}.request({serializedRequest})"; var result = await InvokeAsync(command); +#endif + _webMidiAccessible = bool.Parse(result); + return _webMidiAccessible; } + +#if NET7_0_OR_GREATER + internal static partial class NativeMethods + { + [JSImport("globalThis.Uno.Devices.Midi.Internal.WasmMidiAccess.request")] + internal static partial Task RequestAsync(bool exclusive); + } +#endif } }