From 752c298ef3d1e225fffba45fb3958c23ad0300a5 Mon Sep 17 00:00:00 2001
From: Jeremy Sinclair <4016293+snickler@users.noreply.github.com>
Date: Mon, 4 Sep 2023 11:16:58 -0400
Subject: [PATCH] [PTRun][System] Sort NetworkInterfaces by IPv4, then IPv6
(#28220)
Updated GetList method to sort by IPv4, then IPv6 adapter interfaces to match test logic
---
.../Components/NetworkConnectionProperties.cs | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
index c681ae0e03..d806efdb7a 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs
@@ -143,15 +143,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components
/// List containing all network adapters
internal static List GetList()
{
- List list = new List();
-
- var interfaces = NetworkInterface.GetAllNetworkInterfaces().Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.GetPhysicalAddress() != null);
- foreach (NetworkInterface i in interfaces)
- {
- list.Add(new NetworkConnectionProperties(i));
- }
-
- return list;
+ var interfaces = NetworkInterface.GetAllNetworkInterfaces()
+ .Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.GetPhysicalAddress() != null)
+ .Select(i => new NetworkConnectionProperties(i))
+ .OrderByDescending(i => i.IPv4) // list IPv4 first
+ .ThenBy(i => i.IPv6Primary) // then IPv6
+ .ToList();
+ return interfaces;
}
///