Skip to content

Commit

Permalink
perf(ConnectionProfile): Add HasInternetAccess binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 23, 2023
1 parent ed5ef1b commit 13d39e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
6 changes: 6 additions & 0 deletions src/Uno.UWP/Networking/Connectivity/ConnectionProfile.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 13d39e9

Please sign in to comment.