forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ConnectionProfile): [WPF] Adds support for ConnectionProfile.Get…
…NetworkConnectivityLevel()
- Loading branch information
1 parent
1f3ce90
commit 1eab4e6
Showing
4 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/Uno.UI.Runtime.Skia.Wpf/Extensions/Networking/Connectivity/ConnectionProfileExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Windows.Networking.Connectivity; | ||
|
||
namespace Uno.Extensions.Networking.Connectivity | ||
{ | ||
internal class ConnectionProfileExtension : IConnectionProfileExtension | ||
{ | ||
private readonly object _connectionProfile; | ||
public ConnectionProfileExtension(object owner) | ||
{ | ||
if (!(owner is ConnectionProfile connectionProfile)) | ||
throw new InvalidOperationException($"Owner of {nameof(ConnectionProfileExtension)} must be a {nameof(ConnectionProfile)}."); | ||
|
||
_connectionProfile = connectionProfile; | ||
} | ||
|
||
[DllImport("wininet.dll")] | ||
extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); | ||
|
||
public NetworkConnectivityLevel GetNetworkConnectivityLevel() => | ||
InternetGetConnectedState(out _, 0) ? | ||
NetworkConnectivityLevel.InternetAccess : NetworkConnectivityLevel.None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
src/Uno.UWP/Networking/Connectivity/ConnectionProfile.skia.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
namespace Windows.Networking.Connectivity | ||
using Uno.Foundation.Extensibility; | ||
|
||
namespace Windows.Networking.Connectivity | ||
{ | ||
public partial class ConnectionProfile | ||
{ | ||
private IConnectionProfileExtension _connectionProfileExtension; | ||
|
||
internal static ConnectionProfile GetInternetConnectionProfile() => | ||
new ConnectionProfile(); | ||
|
||
private ConnectionProfile() | ||
{ | ||
} | ||
private ConnectionProfile() => | ||
ApiExtensibility.CreateInstance(this, out _connectionProfileExtension); | ||
|
||
private NetworkConnectivityLevel GetNetworkConnectivityLevelImpl() | ||
{ | ||
return NetworkConnectivityLevel.None; | ||
} | ||
private NetworkConnectivityLevel GetNetworkConnectivityLevelImpl() => | ||
_connectionProfileExtension?.GetNetworkConnectivityLevel() ?? NetworkConnectivityLevel.None; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Uno.UWP/Networking/Connectivity/Internal/IConnectionProfileExtension.skia.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Windows.Networking.Connectivity | ||
{ | ||
internal interface IConnectionProfileExtension | ||
{ | ||
NetworkConnectivityLevel GetNetworkConnectivityLevel(); | ||
} | ||
} |