Skip to content

Commit

Permalink
perf(AnalyticsInfo): Add GetDeviceType binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 21, 2023
1 parent 9cdf0b7 commit 6146848
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Uno.UWP/System/Profile/AnalyticsInfo.Interop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
10 changes: 9 additions & 1 deletion src/Uno.UWP/System/Profile/AnalyticsInfo.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6146848

Please sign in to comment.