From 614684842817e2ca52b1d03df80f109c877e1b7e Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Sun, 21 May 2023 14:17:02 -0400 Subject: [PATCH] perf(AnalyticsInfo): Add GetDeviceType binding --- .../System/Profile/AnalyticsInfo.Interop.wasm.cs | 6 +++++- src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Uno.UWP/System/Profile/AnalyticsInfo.Interop.wasm.cs b/src/Uno.UWP/System/Profile/AnalyticsInfo.Interop.wasm.cs index 1b6547e50bd2..f4140e10634f 100644 --- a/src/Uno.UWP/System/Profile/AnalyticsInfo.Interop.wasm.cs +++ b/src/Uno.UWP/System/Profile/AnalyticsInfo.Interop.wasm.cs @@ -7,7 +7,11 @@ internal partial class AnalyticsInfo { internal static partial class NativeMethods { + private const string JsType = "globalThis.Windows.System.Profile.AnalyticsInfo"; + + [JSImport($"{JsType}.getDeviceType")] + internal static partial string GetDeviceType(); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs b/src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs index 6952b010b680..119bf795e285 100644 --- a/src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs +++ b/src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs @@ -10,11 +10,19 @@ namespace Windows.System.Profile { public static partial class AnalyticsInfo { +#if !NET7_0_OR_GREATER private const string JsType = "Windows.System.Profile.AnalyticsInfo"; +#endif private static UnoDeviceForm GetDeviceForm() { - var typeString = WebAssemblyRuntime.InvokeJS($"{JsType}.getDeviceType()"); + var typeString = +#if NET7_0_OR_GREATER + NativeMethods.GetDeviceType(); +#else + WebAssemblyRuntime.InvokeJS($"{JsType}.getDeviceType()"); +#endif + if (Enum.TryParse(typeString, true, out UnoDeviceForm deviceForm)) { return deviceForm;