From 75a8676910126d1a16f3fb07215379feffe309cf Mon Sep 17 00:00:00 2001 From: Shresht Srivastav <59516096+Shresht7@users.noreply.github.com> Date: Tue, 31 Mar 2026 17:20:15 +0530 Subject: [PATCH] Add reload functionality to update favorites in predictor after modifications --- Module/Public/Add-PSFavorite.ps1 | 1 + Module/Public/Optimize-PSFavorites.ps1 | 1 + Module/Public/Remove-PSFavorite.ps1 | 1 + Predictor/PSFavoritePredictor.cs | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/Module/Public/Add-PSFavorite.ps1 b/Module/Public/Add-PSFavorite.ps1 index a7875e5..f9108c3 100644 --- a/Module/Public/Add-PSFavorite.ps1 +++ b/Module/Public/Add-PSFavorite.ps1 @@ -24,4 +24,5 @@ function Add-PSFavorite( [string] $FavoritesPath = $Script:FavoritesPath ) { $Command | Out-File -FilePath $FavoritesPath -Append + [PSFavorite.PSFavoritePredictor]::Reload() } diff --git a/Module/Public/Optimize-PSFavorites.ps1 b/Module/Public/Optimize-PSFavorites.ps1 index fbb71a2..05575fc 100644 --- a/Module/Public/Optimize-PSFavorites.ps1 +++ b/Module/Public/Optimize-PSFavorites.ps1 @@ -23,5 +23,6 @@ function Optimize-PSFavorites( end { $Favorites | Out-File -FilePath $FavoritesPath + [PSFavorite.PSFavoritePredictor]::Reload() } } diff --git a/Module/Public/Remove-PSFavorite.ps1 b/Module/Public/Remove-PSFavorite.ps1 index 2ae445b..842d431 100644 --- a/Module/Public/Remove-PSFavorite.ps1 +++ b/Module/Public/Remove-PSFavorite.ps1 @@ -49,6 +49,7 @@ function Remove-PSFavorite { if ($PSCmdlet.ShouldProcess("Save changes to the favorites list?")) { $Favorites | Out-File -FilePath $FavoritesPath Write-Verbose "Changes saved to the favorites list." + [PSFavorite.PSFavoritePredictor]::Reload() } } diff --git a/Predictor/PSFavoritePredictor.cs b/Predictor/PSFavoritePredictor.cs index d3c87be..f8ea691 100644 --- a/Predictor/PSFavoritePredictor.cs +++ b/Predictor/PSFavoritePredictor.cs @@ -84,6 +84,15 @@ public static void Initialize(string favoritesPath) LoadFavoritesIfExists(); } + /// + /// Reload the favorites from the file. Call this after modifying the favorites file + /// to immediately reflect changes in the predictor. + /// + public static void Reload() + { + LoadFavoritesIfExists(); + } + /// /// Load the favorites from the file if it exists. If any error occurs, set favorites to an empty array. ///