mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Improve thread safety and simplify monitor management
Refactored `DisplayChangeWatcher` to enhance thread safety by introducing `_initialEnumerationComplete` and ensuring state changes and event handling are dispatched to the UI thread. Removed `MonitorListChangedEventArgs` and the `MonitorsChanged` event from `MonitorManager`, simplifying monitor management logic. Updated `MainViewModel` to remove its dependency on `MonitorsChanged`. Cleaned up `TrayIconService` by removing unused `_showWindowAction` and simplifying resource fallback logic. Fixed minor wording inconsistencies in XML documentation. These changes improve maintainability, thread safety, and performance.
This commit is contained in:
@@ -34,8 +34,6 @@ namespace PowerDisplay.Helpers
|
||||
|
||||
public IReadOnlyList<Monitor> Monitors => _monitors.AsReadOnly();
|
||||
|
||||
public event EventHandler<MonitorListChangedEventArgs>? MonitorsChanged;
|
||||
|
||||
public MonitorManager()
|
||||
{
|
||||
// Initialize controllers
|
||||
@@ -313,16 +311,6 @@ namespace PowerDisplay.Helpers
|
||||
}
|
||||
|
||||
// Trigger change events
|
||||
var addedMonitors = newMonitors.Where(m => !oldMonitors.Any(o => o.Id == m.Id)).ToList();
|
||||
var removedMonitors = oldMonitors.Where(o => !newMonitors.Any(m => m.Id == o.Id)).ToList();
|
||||
|
||||
if (addedMonitors.Count > 0 || removedMonitors.Count > 0)
|
||||
{
|
||||
MonitorsChanged?.Invoke(this, new MonitorListChangedEventArgs(
|
||||
addedMonitors.AsReadOnly(),
|
||||
removedMonitors.AsReadOnly(),
|
||||
_monitors.AsReadOnly()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user