Skip to content

Commit

Permalink
perf: Add RequestAsync binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Jun 9, 2023
1 parent 6a75970 commit 1a6e598
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Uno.UWP/Devices/Midi/Internal/WasmMidiAccess.wasm.cs
Expand Up @@ -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
{
/// <summary>
/// Handles WASM MIDI access permission request
/// </summary>
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;

Expand All @@ -23,11 +30,26 @@ public static async Task<bool> 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<string> RequestAsync(bool exclusive);
}
#endif
}
}

0 comments on commit 1a6e598

Please sign in to comment.