Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -32,8 +33,9 @@ namespace NETworkManager.ViewModels;
public class NetworkInterfaceViewModel : ViewModelBase, IProfileManager
{
#region Variables

private static readonly ILog Log = LogManager.GetLogger(typeof(NetworkInterfaceViewModel));

private readonly IDialogCoordinator _dialogCoordinator;
private readonly DispatcherTimer _searchDispatcherTimer = new();
private BandwidthMeter _bandwidthMeter;
Expand Down Expand Up @@ -118,9 +120,9 @@ private set

#region NetworkInterfaces, SelectedNetworkInterface

private List<NetworkInterfaceInfo> _networkInterfaces;
private ObservableCollection<NetworkInterfaceInfo> _networkInterfaces = [];

public List<NetworkInterfaceInfo> NetworkInterfaces
public ObservableCollection<NetworkInterfaceInfo> NetworkInterfaces
{
get => _networkInterfaces;
private set
Expand Down Expand Up @@ -629,7 +631,8 @@ private async Task LoadNetworkInterfaces()
{
IsNetworkInterfaceLoading = true;

NetworkInterfaces = await NetworkInterface.GetNetworkInterfacesAsync();
// Get all network interfaces...
(await NetworkInterface.GetNetworkInterfacesAsync()).ForEach(NetworkInterfaces.Add);

// Get the last selected interface, if it is still available on this machine...
if (NetworkInterfaces.Count > 0)
Expand Down Expand Up @@ -695,7 +698,7 @@ private async Task ExportAction()
catch (Exception ex)
{
Log.Error("Error while exporting data as " + instance.FileType, ex);

var settings = AppearanceManager.MetroDialog;
settings.AffirmativeButtonText = Strings.OK;

Expand Down Expand Up @@ -935,22 +938,36 @@ private async Task RemoveIPv4AddressAction()

private async void ReloadNetworkInterfaces()
{
// Avoid multiple reloads
if(IsNetworkInterfaceLoading)
return;

IsNetworkInterfaceLoading = true;

// Make the user happy, let him see a reload animation (and he cannot spam the reload command)
await Task.Delay(2000);

var id = string.Empty;

if (SelectedNetworkInterface != null)
id = SelectedNetworkInterface.Id;

// Load network interfaces...
var networkItems = await Models.Network.NetworkInterface.GetNetworkInterfacesAsync();

// Change interface...
SelectedNetworkInterface = string.IsNullOrEmpty(id) ? networkItems.FirstOrDefault() : networkItems.FirstOrDefault(x => x.Id == id);
NetworkInterfaces = networkItems;
// Store the last selected id
var id = SelectedNetworkInterface?.Id ?? string.Empty;

// Get all network interfaces...
var networkInterfaces = await NetworkInterface.GetNetworkInterfacesAsync();

// Invoke on UI thread synchronously
Application.Current.Dispatcher.Invoke(() =>
{
// Clear the list
NetworkInterfaces.Clear();

// Add all network interfaces to the list
networkInterfaces.ForEach(NetworkInterfaces.Add);
});

// Set the last selected interface, if it is still available on this machine...
SelectedNetworkInterface = string.IsNullOrEmpty(id)
? NetworkInterfaces.FirstOrDefault()
: NetworkInterfaces.FirstOrDefault(x => x.Id == id);

IsNetworkInterfaceLoading = false;
}

Expand Down
6 changes: 5 additions & 1 deletion Website/docs/changelog/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ Release date: **xx.xx.2025**

**PuTTY**

- Find `putty.exe` and `powershell.exe` executable by path, similar to `where.exe`. [#2962](https://github.com/BornToBeRoot/NETworkManager/pull/2962)
- Find `putty.exe` executable by path, similar to `where.exe`. [#2962](https://github.com/BornToBeRoot/NETworkManager/pull/2962)

**AWS Session Manager**

- Find `pwsh.exe` and `powershell.exe` executable by path, similar to `where.exe`. [#2962](https://github.com/BornToBeRoot/NETworkManager/pull/2962)

## Bugfixes

**Network Interface**

- Re-select the network interface after a network change or configuration update. Thanks to [@Ghislain1](https://github.com/Ghislain1) [#3004](https://github.com/BornToBeRoot/NETworkManager/pull/3004) [#2962](https://github.com/BornToBeRoot/NETworkManager/pull/2962)

## Dependencies, Refactoring & Documentation

- Code cleanup & refactoring
Expand Down