mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Refactor DDC monitor discovery; clarify interface docs
Refactored DiscoverMonitorsAsync in DdcCiController to remove Task.Run and simplify async flow and error handling. Updated XML doc for Name property in IMonitorController to clarify its purpose.
This commit is contained in:
@@ -370,43 +370,38 @@ namespace PowerDisplay.Common.Drivers.DDC
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<IEnumerable<Monitor>> DiscoverMonitorsAsync(CancellationToken cancellationToken = default)
|
public async Task<IEnumerable<Monitor>> DiscoverMonitorsAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return await Task.Run(
|
try
|
||||||
async () =>
|
{
|
||||||
|
// Get monitor display info from QueryDisplayConfig, keyed by device path (unique per target)
|
||||||
|
var allMonitorDisplayInfo = DdcCiNative.GetAllMonitorDisplayInfo();
|
||||||
|
|
||||||
|
// Phase 1: Collect candidate monitors
|
||||||
|
var monitorHandles = EnumerateMonitorHandles();
|
||||||
|
if (monitorHandles.Count == 0)
|
||||||
{
|
{
|
||||||
try
|
return Enumerable.Empty<Monitor>();
|
||||||
{
|
}
|
||||||
// Get monitor display info from QueryDisplayConfig, keyed by device path (unique per target)
|
|
||||||
var allMonitorDisplayInfo = DdcCiNative.GetAllMonitorDisplayInfo();
|
|
||||||
|
|
||||||
// Phase 1: Collect candidate monitors
|
var candidateMonitors = await CollectCandidateMonitorsAsync(
|
||||||
var monitorHandles = EnumerateMonitorHandles();
|
monitorHandles, allMonitorDisplayInfo, cancellationToken);
|
||||||
if (monitorHandles.Count == 0)
|
|
||||||
{
|
|
||||||
return Enumerable.Empty<Monitor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var candidateMonitors = await CollectCandidateMonitorsAsync(
|
if (candidateMonitors.Count == 0)
|
||||||
monitorHandles, allMonitorDisplayInfo, cancellationToken);
|
{
|
||||||
|
return Enumerable.Empty<Monitor>();
|
||||||
|
}
|
||||||
|
|
||||||
if (candidateMonitors.Count == 0)
|
// Phase 2: Fetch capabilities in parallel
|
||||||
{
|
var fetchResults = await FetchCapabilitiesInParallelAsync(
|
||||||
return Enumerable.Empty<Monitor>();
|
candidateMonitors, cancellationToken);
|
||||||
}
|
|
||||||
|
|
||||||
// Phase 2: Fetch capabilities in parallel
|
// Phase 3: Create monitor objects
|
||||||
var fetchResults = await FetchCapabilitiesInParallelAsync(
|
return CreateValidMonitors(fetchResults);
|
||||||
candidateMonitors, cancellationToken);
|
}
|
||||||
|
catch (Exception ex)
|
||||||
// Phase 3: Create monitor objects
|
{
|
||||||
return CreateValidMonitors(fetchResults);
|
Logger.LogError($"DDC: DiscoverMonitorsAsync exception: {ex.Message}\nStack: {ex.StackTrace}");
|
||||||
}
|
return Enumerable.Empty<Monitor>();
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
|
||||||
Logger.LogError($"DDC: DiscoverMonitorsAsync exception: {ex.Message}\nStack: {ex.StackTrace}");
|
|
||||||
return Enumerable.Empty<Monitor>();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace PowerDisplay.Common.Interfaces
|
|||||||
public interface IMonitorController
|
public interface IMonitorController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controller name
|
/// Gets controller name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user