From 639e5f5e1694d5cc71bdf88b61850f3b659310a2 Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Thu, 28 Nov 2024 00:42:27 +0100 Subject: [PATCH 1/3] Fix: Improve search / remove converters --- ...ationTypeToHumanReadableStringConverter.cs | 23 ------------- ...CenterFrequencyToChannelStringConverter.cs | 18 ----------- .../WiFiPhyKindToStringConverter.cs | 20 ------------ Source/NETworkManager.Models/Network/WiFi.cs | 4 +++ .../Network/WiFiNetworkInfo.cs | 18 +++++++++-- .../ViewModels/WiFiViewModel.cs | 11 ++++--- Source/NETworkManager/Views/WiFiView.xaml | 32 ++++++++----------- Website/docs/application/wifi.md | 2 +- 8 files changed, 40 insertions(+), 88 deletions(-) delete mode 100644 Source/NETworkManager.Converters/WiFiAuthenticationTypeToHumanReadableStringConverter.cs delete mode 100644 Source/NETworkManager.Converters/WiFiChannelCenterFrequencyToChannelStringConverter.cs delete mode 100644 Source/NETworkManager.Converters/WiFiPhyKindToStringConverter.cs diff --git a/Source/NETworkManager.Converters/WiFiAuthenticationTypeToHumanReadableStringConverter.cs b/Source/NETworkManager.Converters/WiFiAuthenticationTypeToHumanReadableStringConverter.cs deleted file mode 100644 index 06868a4a98..0000000000 --- a/Source/NETworkManager.Converters/WiFiAuthenticationTypeToHumanReadableStringConverter.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Globalization; -using System.Windows.Data; -using Windows.Networking.Connectivity; -using NETworkManager.Models.Network; - -namespace NETworkManager.Converters; - -public sealed class WiFiAuthenticationTypeToHumanReadableStringConverter : IValueConverter -{ - /* Translate the name of the accent */ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value is not NetworkAuthenticationType type - ? "-/-" - : $"{WiFi.GetHumanReadableNetworkAuthenticationType(type)}"; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/Source/NETworkManager.Converters/WiFiChannelCenterFrequencyToChannelStringConverter.cs b/Source/NETworkManager.Converters/WiFiChannelCenterFrequencyToChannelStringConverter.cs deleted file mode 100644 index a061d751dd..0000000000 --- a/Source/NETworkManager.Converters/WiFiChannelCenterFrequencyToChannelStringConverter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Globalization; -using System.Windows.Data; - -namespace NETworkManager.Converters; - -public sealed class WiFiChannelCenterFrequencyToChannelStringConverter : IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value is not int channel ? "-/-" : $"{channel}"; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/Source/NETworkManager.Converters/WiFiPhyKindToStringConverter.cs b/Source/NETworkManager.Converters/WiFiPhyKindToStringConverter.cs deleted file mode 100644 index 6e0eef97bf..0000000000 --- a/Source/NETworkManager.Converters/WiFiPhyKindToStringConverter.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Globalization; -using System.Windows.Data; -using Windows.Devices.WiFi; -using NETworkManager.Models.Network; - -namespace NETworkManager.Converters; - -public sealed class WiFiPhyKindToStringConverter : IValueConverter -{ - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - return value is not WiFiPhyKind phyKind ? "-/-" : $"{WiFi.GetHumanReadablePhyKind(phyKind)}"; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/Source/NETworkManager.Models/Network/WiFi.cs b/Source/NETworkManager.Models/Network/WiFi.cs index 3c5af19d2d..0066ee502a 100644 --- a/Source/NETworkManager.Models/Network/WiFi.cs +++ b/Source/NETworkManager.Models/Network/WiFi.cs @@ -6,6 +6,7 @@ using Windows.Devices.WiFi; using Windows.Networking.Connectivity; using Windows.Security.Credentials; +using NETworkManager.Models.Lookup; namespace NETworkManager.Models.Network; @@ -81,6 +82,9 @@ public static async Task GetNetworksAsync(WiFiAdapter adapt Channel = GetChannelFromChannelFrequency(channelFrequencyInGigahertz), IsHidden = string.IsNullOrEmpty(availableNetwork.Ssid), IsConnected = availableNetwork.Bssid.Equals(bssid, StringComparison.OrdinalIgnoreCase), + NetworkAuthenticationType = GetHumanReadableNetworkAuthenticationType(availableNetwork.SecuritySettings.NetworkAuthenticationType), + Vendor = (await OUILookup.LookupByMacAddressAsync(availableNetwork.Bssid)).FirstOrDefault()?.Vendor ?? "-/-", + PhyKind = GetHumanReadablePhyKind(availableNetwork.PhyKind) }; wifiNetworkInfos.Add(wifiNetworkInfo); diff --git a/Source/NETworkManager.Models/Network/WiFiNetworkInfo.cs b/Source/NETworkManager.Models/Network/WiFiNetworkInfo.cs index 20c61a38fd..6c94b8ffa5 100644 --- a/Source/NETworkManager.Models/Network/WiFiNetworkInfo.cs +++ b/Source/NETworkManager.Models/Network/WiFiNetworkInfo.cs @@ -25,10 +25,10 @@ public WiFiNetworkInfo() /// /// Radio that is used like 2.4 GHz, 5 GHz, etc. /// - public WiFiRadio Radio { get; set; } + public WiFiRadio Radio { get; init; } /// - /// The channel center frequency in Gigahertz. + /// The channel center frequency in Gigahertz like 2.4 GHz, 5 GHz, etc. /// public double ChannelCenterFrequencyInGigahertz { get; set; } @@ -47,5 +47,19 @@ public WiFiNetworkInfo() /// public bool IsConnected { get; set; } + /// + /// Human-readable network authentication type. + /// + public string NetworkAuthenticationType { get; set; } + + /// + /// Vendor of the Wi-Fi network like Cisco, Netgear, etc. + /// + public string Vendor { get; set; } + + /// + /// Human-readable phy kind. + /// + public string PhyKind { get; set; } #endregion } \ No newline at end of file diff --git a/Source/NETworkManager/ViewModels/WiFiViewModel.cs b/Source/NETworkManager/ViewModels/WiFiViewModel.cs index c7e0ea52e8..93aad6ce3c 100644 --- a/Source/NETworkManager/ViewModels/WiFiViewModel.cs +++ b/Source/NETworkManager/ViewModels/WiFiViewModel.cs @@ -84,7 +84,7 @@ public bool IsAdaptersLoading } } - private List _adapters = new(); + private List _adapters = []; public List Adapters { @@ -487,13 +487,14 @@ public WiFiViewModel(IDialogCoordinator instance) if (string.IsNullOrEmpty(Search)) return true; - // Search by: SSID, Security, Channel, BSSID (MAC address), Vendor, Phy kind + // Search by: SSID, Security, Frequency , Channel, BSSID (MAC address), Vendor, Phy kind return info.AvailableNetwork.Ssid.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || - WiFi.GetHumanReadableNetworkAuthenticationType(info.AvailableNetwork.SecuritySettings.NetworkAuthenticationType).IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || + info.NetworkAuthenticationType.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || + $"{info.ChannelCenterFrequencyInGigahertz}".IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || $"{info.Channel}".IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || info.AvailableNetwork.Bssid.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || - OUILookup.LookupByMacAddress(info.AvailableNetwork.Bssid).FirstOrDefault()?.Vendor.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || - WiFi.GetHumanReadablePhyKind(info.AvailableNetwork.PhyKind).IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1; + info.Vendor.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1 || + info.PhyKind.IndexOf(Search, StringComparison.OrdinalIgnoreCase) > -1; }; // Load network adapters diff --git a/Source/NETworkManager/Views/WiFiView.xaml b/Source/NETworkManager/Views/WiFiView.xaml index c7c228893e..6a4d21ffdb 100644 --- a/Source/NETworkManager/Views/WiFiView.xaml +++ b/Source/NETworkManager/Views/WiFiView.xaml @@ -27,18 +27,12 @@ - - - - @@ -306,7 +300,7 @@ Style="{StaticResource ResourceKey=CopyMenuItem}" /> + Binding="{Binding Path=(network:WiFiNetworkInfo.NetworkAuthenticationType)}" + SortMemberPath="NetworkAuthenticationType" /> + SortMemberPath="ChannelCenterFrequencyInGigahertz" /> + Binding="{Binding Path=(network:WiFiNetworkInfo.Channel)}" + SortMemberPath="Channel" /> + Binding="{Binding Path=(network:WiFiNetworkInfo.Vendor)}" + SortMemberPath="Vendor" /> + Binding="{Binding Path=(network:WiFiNetworkInfo.PhyKind)}" + SortMemberPath="PhyKind" /> Date: Thu, 28 Nov 2024 00:44:56 +0100 Subject: [PATCH 2/3] Docs: #2940 --- Website/docs/changelog/next-release.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Website/docs/changelog/next-release.md b/Website/docs/changelog/next-release.md index 030e909e81..935f9e3a12 100644 --- a/Website/docs/changelog/next-release.md +++ b/Website/docs/changelog/next-release.md @@ -28,6 +28,9 @@ Release date: **xx.xx.2024** ## Improvements +- **WiFi** + - Improve search, cleanup/remove some converters to make the code more readable and faster. [#2940](https://github.com/BornToBeRoot/NETworkManager/pull/2940) + ## Bugfixes - Changed the Welcome dialog from `MahApps.Metro.Controls.Dialogs` to `MahApps.Metro.SimpleChildWindow`, so the main window can be dragged and resized on the first start. [#2914](https://github.com/BornToBeRoot/NETworkManager/pull/2914) From e794820fce849e7161fa37f4dc512913c3890486 Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Thu, 28 Nov 2024 00:45:34 +0100 Subject: [PATCH 3/3] Docs: #2940 --- Website/docs/changelog/next-release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Website/docs/changelog/next-release.md b/Website/docs/changelog/next-release.md index 935f9e3a12..73d643cef5 100644 --- a/Website/docs/changelog/next-release.md +++ b/Website/docs/changelog/next-release.md @@ -40,6 +40,6 @@ Release date: **xx.xx.2024** ## Dependencies, Refactoring & Documentation -- Code cleanup & refactoring +- Code cleanup & refactoring [#2940](https://github.com/BornToBeRoot/NETworkManager/pull/2940) - Language files updated via [#transifex](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Ftransifex-integration) - Dependencies updated via [#dependabot](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Fdependabot)