Remove batch notification support from MonitorInfo

Removed SuspendNotifications, NotificationResumer, and the custom OnPropertyChanged override from MonitorInfo. Property changes now trigger immediate notifications instead of batching updates for UI refresh. This simplifies the class and notification logic.
This commit is contained in:
Yu Leng
2025-12-12 11:01:13 +08:00
parent f47abb43e9
commit dea4cbd045

View File

@@ -49,73 +49,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library
private ObservableCollection<ColorPresetItem> _colorPresetsForDisplayCache;
private int _lastColorTemperatureVcpForCache = -1;
// Batch update support to reduce PropertyChanged notifications during bulk updates
private bool _suppressNotifications;
private bool _hasPendingNotifications;
/// <summary>
/// Suspends PropertyChanged notifications until the returned object is disposed.
/// When disposed, a single PropertyChanged with empty string is raised to refresh all bindings.
/// Use this when updating multiple properties at once to improve UI performance.
/// </summary>
/// <example>
/// using (monitor.SuspendNotifications())
/// {
/// monitor.CurrentBrightness = newBrightness;
/// monitor.ColorTemperatureVcp = newTemp;
/// } // Single UI refresh here
/// </example>
public IDisposable SuspendNotifications()
{
_suppressNotifications = true;
_hasPendingNotifications = false;
return new NotificationResumer(this);
}
/// <summary>
/// Helper class to resume notifications when disposed.
/// </summary>
private sealed class NotificationResumer : IDisposable
{
private readonly MonitorInfo _owner;
private bool _disposed;
public NotificationResumer(MonitorInfo owner) => _owner = owner;
public void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
_owner._suppressNotifications = false;
// If any property changed during suspension, raise a single notification to refresh all
if (_owner._hasPendingNotifications)
{
_owner._hasPendingNotifications = false;
_owner.OnPropertyChanged(string.Empty);
}
}
}
/// <summary>
/// Raises PropertyChanged if notifications are not suppressed.
/// Tracks pending notifications during batch updates.
/// </summary>
protected new void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
{
if (_suppressNotifications)
{
_hasPendingNotifications = true;
return;
}
base.OnPropertyChanged(propertyName);
}
/// <summary>
/// Invalidates the color preset cache and notifies property changes.
/// Call this when VcpCodesFormatted or SupportsColorTemperature changes.