Skip to content

Commit

Permalink
Fix #267
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot committed Jan 30, 2020
1 parent 3d33820 commit 2c8fa30
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 508 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/NETworkManager/Resources/Localization/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2587,4 +2587,7 @@ URL: https://github.com/BornToBeRoot/NETworkManager/tree/master/Documentation</v
<data name="WebViewControlCertificateIsInvalidMessage" xml:space="preserve">
<value>The WebView control (Microsoft Edge) cannot connect to websites with an invalid certificate!</value>
</data>
<data name="MicrosoftWindowsSDKContractsIsNotAvailable" xml:space="preserve">
<value>Microsoft.Windows.SDK.Contracts is required for this feature but not available on this system (e.g. on Windows Server).</value>
</data>
</root>
48 changes: 38 additions & 10 deletions Source/NETworkManager/ViewModels/WiFiViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Data;
Expand All @@ -23,6 +24,20 @@ public class WiFiViewModel : ViewModelBase
private readonly DispatcherTimer _autoRefreshTimer = new DispatcherTimer();
private bool _isTimerPaused;

private bool _sdkContractsFailedToLoad;
public bool SDKContractsFailedToLoad
{
get => _sdkContractsFailedToLoad;
set
{
if (value == _sdkContractsFailedToLoad)
return;

_sdkContractsFailedToLoad = value;
OnPropertyChanged();
}
}

private bool _isAdaptersLoading;
public bool IsAdaptersLoading
{
Expand Down Expand Up @@ -174,7 +189,6 @@ public bool Show2dot4GHzNetworks
}
}


private bool _show5GHzNetworks;
public bool Show5GHzNetworks
{
Expand Down Expand Up @@ -306,14 +320,21 @@ private async void LoadAdapters()
{
IsAdaptersLoading = true;

Adapters = await WiFi.GetAdapterAsync();

// Get the last selected interface, if it is still available on this machine...
if (Adapters.Count > 0)
try
{
var info = Adapters.FirstOrDefault(s => s.NetworkInterfaceInfo.Id.ToString() == SettingsManager.Current.WiFi_InterfaceId);
Adapters = await WiFi.GetAdapterAsync();

// Get the last selected interface, if it is still available on this machine...
if (Adapters.Count > 0)
{
var info = Adapters.FirstOrDefault(s => s.NetworkInterfaceInfo.Id.ToString() == SettingsManager.Current.WiFi_InterfaceId);

SelectedAdapter = info ?? Adapters[0];
SelectedAdapter = info ?? Adapters[0];
}
}
catch (FileNotFoundException) // This exception is thrown, when the Microsoft.Windows.SDK.Contracts is not available...
{
SDKContractsFailedToLoad = true;
}

IsAdaptersLoading = false;
Expand All @@ -330,10 +351,17 @@ await Task.Delay(2000); // Make the user happy, let him see a reload animation (
if (SelectedAdapter != null)
id = SelectedAdapter.NetworkInterfaceInfo.Id;

Adapters = await WiFi.GetAdapterAsync();
try
{
Adapters = await WiFi.GetAdapterAsync();

if (Adapters.Count > 0)
SelectedAdapter = string.IsNullOrEmpty(id) ? Adapters.FirstOrDefault() : Adapters.FirstOrDefault(x => x.NetworkInterfaceInfo.Id == id);
if (Adapters.Count > 0)
SelectedAdapter = string.IsNullOrEmpty(id) ? Adapters.FirstOrDefault() : Adapters.FirstOrDefault(x => x.NetworkInterfaceInfo.Id == id);
}
catch (FileNotFoundException) // This exception is thrown, when the Microsoft.Windows.SDK.Contracts is not available...
{
SDKContractsFailedToLoad = true;
}

IsAdaptersLoading = false;
}
Expand Down

0 comments on commit 2c8fa30

Please sign in to comment.