mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
Improve logging, synchronization, and process handling
Enhanced logging for event handling, settings updates, and process management to improve traceability and debugging. - Added detailed logging and exception handling in `NativeEventWaiter.cs` for event listener setup and execution. - Updated `MainViewModel.Settings.cs` to synchronize monitor settings and save changes after applying color temperature. - Improved process management in `dllmain.cpp` to ensure `PowerDisplay` is running before signaling events, with added race condition prevention. - Removed redundant settings update signaling in `dllmain.cpp` to avoid excessive UI refreshes and dropdown closures. - Enhanced monitor synchronization in `PowerDisplayViewModel.cs` to handle pending operations and prevent stale data overwrites. - General improvements in error handling and logging across all changes.
This commit is contained in:
@@ -378,6 +378,18 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
var updatedSettings = SettingsUtils.GetSettingsOrDefault<PowerDisplaySettings>(PowerDisplaySettings.ModuleName);
|
||||
var updatedMonitors = updatedSettings.Properties.Monitors;
|
||||
|
||||
// Check for pending color temperature operation to avoid race conditions
|
||||
// If there's a pending operation, we should preserve the local ColorTemperatureVcp value
|
||||
// because the Settings UI just set it and PowerDisplay hasn't processed it yet
|
||||
var pendingColorTempOp = updatedSettings.Properties.PendingColorTemperatureOperation;
|
||||
var pendingColorTempMonitorId = pendingColorTempOp?.MonitorId;
|
||||
var pendingColorTempValue = pendingColorTempOp?.ColorTemperatureVcp ?? 0;
|
||||
|
||||
if (!string.IsNullOrEmpty(pendingColorTempMonitorId))
|
||||
{
|
||||
Logger.LogInfo($"[ReloadMonitors] Found pending color temp operation for monitor: {pendingColorTempMonitorId}, will preserve local value");
|
||||
}
|
||||
|
||||
Logger.LogInfo($"[ReloadMonitors] Loaded {updatedMonitors.Count} monitors from settings");
|
||||
|
||||
// Parse capabilities for each monitor
|
||||
@@ -406,7 +418,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
// Monitor still exists - update its properties in place
|
||||
Logger.LogInfo($"[ReloadMonitors] Updating existing monitor: {existingMonitor.InternalName}");
|
||||
existingMonitor.UpdateFrom(updatedMonitor);
|
||||
|
||||
// Preserve local ColorTemperatureVcp if there's a pending operation for this monitor
|
||||
// This prevents race condition where PowerDisplay's stale data overwrites user's selection
|
||||
if (existingMonitor.InternalName == pendingColorTempMonitorId && pendingColorTempValue > 0)
|
||||
{
|
||||
var preservedColorTemp = existingMonitor.ColorTemperatureVcp;
|
||||
existingMonitor.UpdateFrom(updatedMonitor);
|
||||
existingMonitor.ColorTemperatureVcp = preservedColorTemp;
|
||||
Logger.LogInfo($"[ReloadMonitors] Preserved local ColorTemperatureVcp: 0x{preservedColorTemp:X2} for monitor with pending operation");
|
||||
}
|
||||
else
|
||||
{
|
||||
existingMonitor.UpdateFrom(updatedMonitor);
|
||||
}
|
||||
|
||||
updatedMonitorsDict.Remove(existingMonitor.InternalName);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user