From a841dd249bbdf385c7101ae1587d59838b25588c Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Wed, 31 May 2023 00:30:24 -0400 Subject: [PATCH] perf: Add Gyrometer bindings --- .../Devices/Sensors/Gyrometer.Interop.wasm.cs | 12 +++++++++++- src/Uno.UWP/Devices/Sensors/Gyrometer.wasm.cs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Uno.UWP/Devices/Sensors/Gyrometer.Interop.wasm.cs b/src/Uno.UWP/Devices/Sensors/Gyrometer.Interop.wasm.cs index 5fc7bb29f1d4..3a1983f0655a 100644 --- a/src/Uno.UWP/Devices/Sensors/Gyrometer.Interop.wasm.cs +++ b/src/Uno.UWP/Devices/Sensors/Gyrometer.Interop.wasm.cs @@ -7,7 +7,17 @@ internal partial class Gyrometer { internal static partial class NativeMethods { + private const string JsType = "globalThis.Windows.Devices.Sensors.Gyrometer"; + + [JSImport($"{JsType}.initialize")] + internal static partial bool Initialize(); + + [JSImport($"{JsType}.startReading")] + internal static partial void StartReading(); + + [JSImport($"{JsType}.stopReading")] + internal static partial void StopReading(); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/Devices/Sensors/Gyrometer.wasm.cs b/src/Uno.UWP/Devices/Sensors/Gyrometer.wasm.cs index 3b95156d2bcf..3f03db8a0fed 100644 --- a/src/Uno.UWP/Devices/Sensors/Gyrometer.wasm.cs +++ b/src/Uno.UWP/Devices/Sensors/Gyrometer.wasm.cs @@ -12,7 +12,9 @@ namespace Windows.Devices.Sensors { public partial class Gyrometer { +#if !NET7_0_OR_GREATER private const string JsType = "Windows.Devices.Sensors.Gyrometer"; +#endif private DateTimeOffset _lastReading = DateTimeOffset.MinValue; @@ -24,6 +26,9 @@ private Gyrometer() private static Gyrometer TryCreateInstance() { +#if NET7_0_OR_GREATER + return NativeMethods.Initialize() ? new() : null; +#else var command = $"{JsType}.initialize()"; var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); if (bool.Parse(initialized) == true) @@ -31,18 +36,27 @@ private static Gyrometer TryCreateInstance() return new Gyrometer(); } return null; +#endif } private void StartReading() { +#if NET7_0_OR_GREATER + NativeMethods.StartReading(); +#else var command = $"{JsType}.startReading()"; Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); +#endif } private void StopReading() { +#if NET7_0_OR_GREATER + NativeMethods.StopReading(); +#else var command = $"{JsType}.stopReading()"; Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); +#endif } ///