From 0c0e6bd243d1892dddb425290394eb0e53949c4f Mon Sep 17 00:00:00 2001 From: Martin Wiethan <47688561+Marterich@users.noreply.github.com> Date: Fri, 23 May 2025 17:56:24 +0200 Subject: [PATCH] Implement search bar debounce functionality to improve UI responsiveness (#3371) * Implement search bar debounce functionality to improve UI responsiveness * Enhance app search functionality to include description matching --- .../private/Find-AppsByNameOrDescription.ps1 | 3 ++- scripts/main.ps1 | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/functions/private/Find-AppsByNameOrDescription.ps1 b/functions/private/Find-AppsByNameOrDescription.ps1 index 44cf48a4..3300d88b 100644 --- a/functions/private/Find-AppsByNameOrDescription.ps1 +++ b/functions/private/Find-AppsByNameOrDescription.ps1 @@ -34,7 +34,8 @@ function Find-AppsByNameOrDescription { if ($_.Tag -like "CategoryWrapPanel_*") { # Search for Apps that match the search string $_.Children | Foreach-Object { - if ($sync.configs.applicationsHashtable.$($_.Tag).Content -like "*$SearchString*") { + $appEntry = $sync.configs.applicationsHashtable.$($_.Tag) + if ($appEntry.Content -like "*$SearchString*" -or $appEntry.Description -like "*$SearchString*") { # Show the App and the parent CategoryWrapPanel if the string is found $_.Visibility = [Windows.Visibility]::Visible $_.parent.Visibility = [Windows.Visibility]::Visible diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 57ad15b0..b779fa02 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -376,12 +376,15 @@ if ($sync["ISOLanguage"].Items.Count -eq 1) { } $sync["ISOLanguage"].SelectedIndex = 0 -$sync["SearchBar"].Add_TextChanged({ - if ($sync.SearchBar.Text -ne "") { - $sync.SearchBarClearButton.Visibility = "Visible" - } else { - $sync.SearchBarClearButton.Visibility = "Collapsed" - } +# The SearchBarTimer is used to delay the search operation until the user has stopped typing for a short period +# This prevents the ui from stuttering when the user types quickly as it dosnt need to update the ui for every keystroke + +$searchBarTimer = New-Object System.Windows.Threading.DispatcherTimer +$searchBarTimer.Interval = [TimeSpan]::FromMilliseconds(300) +$searchBarTimer.IsEnabled = $false + +$searchBarTimer.add_Tick({ + $searchBarTimer.Stop() switch ($sync.currentTab) { "Install" { Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text @@ -391,6 +394,17 @@ $sync["SearchBar"].Add_TextChanged({ } } }) +$sync["SearchBar"].Add_TextChanged({ + if ($sync.SearchBar.Text -ne "") { + $sync.SearchBarClearButton.Visibility = "Visible" + } else { + $sync.SearchBarClearButton.Visibility = "Collapsed" + } + if ($searchBarTimer.IsEnabled) { + $searchBarTimer.Stop() + } + $searchBarTimer.Start() +}) $sync["Form"].Add_Loaded({ param($e)