From b70a0ca883da67402f1f88ea3f61822cdee83004 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Sun, 26 May 2024 23:44:54 +0300 Subject: [PATCH] Fix crash when attempting to change application whitelist Closes #293 --- ...plicationWhitelistSettingsTabView.axaml.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs b/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs index 706468d..7054266 100644 --- a/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs +++ b/LightBulb/Views/Components/Settings/ApplicationWhitelistSettingsTabView.axaml.cs @@ -42,10 +42,25 @@ private void UserControl_OnUnloaded(object? sender, RoutedEventArgs args) => private void WhitelistedApplicationsListBox_OnSelectionChanged( object? sender, SelectionChangedEventArgs args - ) => - DataContext.WhitelistedApplications = WhitelistedApplicationsListBox + ) + { + var applications = WhitelistedApplicationsListBox .SelectedItems?.Cast() .ToArray(); + // Don't update the view model if the list hasn't changed. + // This is important to avoid potential infinite loops. + if ( + applications is not null + && DataContext.WhitelistedApplications is not null + && applications.SequenceEqual(DataContext.WhitelistedApplications) + ) + { + return; + } + + DataContext.WhitelistedApplications = applications; + } + public void Dispose() => _eventRoot.Dispose(); }