From 13d39e94a34ded881c6c727828ee08097ecb1940 Mon Sep 17 00:00:00 2001 From: Elie Bariche <33458222+ebariche@users.noreply.github.com> Date: Tue, 23 May 2023 08:28:00 -0400 Subject: [PATCH] perf(ConnectionProfile): Add HasInternetAccess binding --- .../Connectivity/ConnectionProfile.Interop.wasm.cs | 4 +++- .../Networking/Connectivity/ConnectionProfile.wasm.cs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs index e550a6944563..a5753cff4b6c 100644 --- a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs +++ b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.Interop.wasm.cs @@ -7,7 +7,9 @@ internal partial class ConnectionProfile { internal static partial class NativeMethods { + [JSImport("globalThis.Windows.Networking.Connectivity.ConnectionProfile.hasInternetAccess")] + internal static partial bool HasInternetAccess(); } } } -#endif \ No newline at end of file +#endif diff --git a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs index fb106533716d..5b0ff24b56f0 100644 --- a/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs +++ b/src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs @@ -8,7 +8,9 @@ namespace Windows.Networking.Connectivity { public partial class ConnectionProfile { +#if !NET7_0_OR_GREATER private const string JsType = "Windows.Networking.Connectivity.ConnectionProfile"; +#endif internal static ConnectionProfile GetInternetConnectionProfile() => new ConnectionProfile(); @@ -19,9 +21,13 @@ private ConnectionProfile() private NetworkConnectivityLevel GetNetworkConnectivityLevelImpl() { +#if NET7_0_OR_GREATER + return NativeMethods.HasInternetAccess() ? NetworkConnectivityLevel.InternetAccess : NetworkConnectivityLevel.None; +#else var command = $"{JsType}.hasInternetAccess()"; var result = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command); return bool.Parse(result) ? NetworkConnectivityLevel.InternetAccess : NetworkConnectivityLevel.None; +#endif } } }