Skip to content

Commit

Permalink
feat(ConnectionProfile): [WPF] Adds support for ConnectionProfile.Get…
Browse files Browse the repository at this point in the history
…NetworkConnectivityLevel()
  • Loading branch information
SkyeHoefling committed Jul 12, 2021
1 parent 1f3ce90 commit 1eab4e6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
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;
}
}
3 changes: 3 additions & 0 deletions src/Uno.UI.Runtime.Skia.Wpf/WpfHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
using Uno.UI.Xaml.Core;
using Windows.Graphics.Display;
using Windows.System;
using Windows.Networking.Connectivity;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using WinUI = Windows.UI.Xaml;
using Uno.UI.Xaml.Controls.Extensions;
using Uno.UI.Runtime.Skia.WPF.Extensions.UI.Xaml.Controls;
using Uno.Extensions.System;
using Uno.Extensions.Networking.Connectivity;
using WpfApplication = System.Windows.Application;
using WpfCanvas = System.Windows.Controls.Canvas;
using WpfControl = System.Windows.Controls.Control;
Expand Down Expand Up @@ -58,6 +60,7 @@ static WpfHost()
ApiExtensibility.Register(typeof(Windows.ApplicationModel.DataTransfer.DragDrop.Core.IDragDropExtension), o => new WpfDragDropExtension(o));
ApiExtensibility.Register(typeof(IFileOpenPickerExtension), o => new FileOpenPickerExtension(o));
ApiExtensibility.Register(typeof(IFileSavePickerExtension), o => new FileSavePickerExtension(o));
ApiExtensibility.Register(typeof(IConnectionProfileExtension), o => new ConnectionProfileExtension(o));
ApiExtensibility.Register<TextBoxView>(typeof(ITextBoxViewExtension), o => new TextBoxViewExtension(o));
ApiExtensibility.Register(typeof(ILauncherExtension), o => new LauncherExtension(o));
}
Expand Down
17 changes: 9 additions & 8 deletions src/Uno.UWP/Networking/Connectivity/ConnectionProfile.skia.cs
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Windows.Networking.Connectivity
{
internal interface IConnectionProfileExtension
{
NetworkConnectivityLevel GetNetworkConnectivityLevel();
}
}

0 comments on commit 1eab4e6

Please sign in to comment.