diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/DdcCiController.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/DdcCiController.cs
index 3b864dad7b..f31dbe07f0 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/DdcCiController.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/DDC/DdcCiController.cs
@@ -143,24 +143,12 @@ namespace PowerDisplay.Common.Drivers.DDC
cancellationToken);
}
- ///
- /// Get monitor contrast
- ///
- public Task GetContrastAsync(Monitor monitor, CancellationToken cancellationToken = default)
- => GetVcpFeatureAsync(monitor, NativeConstants.VcpCodeContrast, cancellationToken);
-
///
/// Set monitor contrast
///
public Task SetContrastAsync(Monitor monitor, int contrast, CancellationToken cancellationToken = default)
=> SetVcpFeatureAsync(monitor, NativeConstants.VcpCodeContrast, contrast, 0, 100, cancellationToken);
- ///
- /// Get monitor volume
- ///
- public Task GetVolumeAsync(Monitor monitor, CancellationToken cancellationToken = default)
- => GetVcpFeatureAsync(monitor, NativeConstants.VcpCodeVolume, cancellationToken);
-
///
/// Set monitor volume
///
@@ -441,37 +429,6 @@ namespace PowerDisplay.Common.Drivers.DDC
}
}
- ///
- /// Save current settings
- ///
- public async Task SaveCurrentSettingsAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return await Task.Run(
- () =>
- {
- if (monitor.Handle == IntPtr.Zero)
- {
- return MonitorOperationResult.Failure("Invalid monitor handle");
- }
-
- try
- {
- if (SaveCurrentSettings(monitor.Handle))
- {
- return MonitorOperationResult.Success();
- }
-
- var lastError = GetLastError();
- return MonitorOperationResult.Failure($"Failed to save settings", (int)lastError);
- }
- catch (Exception ex)
- {
- return MonitorOperationResult.Failure($"Exception saving settings: {ex.Message}");
- }
- },
- cancellationToken);
- }
-
///
/// Discover supported monitors
///
@@ -640,17 +597,6 @@ namespace PowerDisplay.Common.Drivers.DDC
cancellationToken);
}
- ///
- /// Validate monitor connection status.
- /// Uses quick VCP read instead of full capabilities retrieval.
- ///
- public async Task ValidateConnectionAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return await Task.Run(
- () => monitor.Handle != IntPtr.Zero && DdcCiNative.QuickConnectionCheck(monitor.Handle),
- cancellationToken);
- }
-
///
/// Get physical monitors with retry logic to handle Windows API occasionally returning NULL handles
///
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/WMI/WmiController.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/WMI/WmiController.cs
index acbdf13707..2a5e6690c6 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/WMI/WmiController.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Drivers/WMI/WmiController.cs
@@ -264,31 +264,6 @@ namespace PowerDisplay.Common.Drivers.WMI
cancellationToken);
}
- ///
- /// Validate monitor connection status
- ///
- public async Task ValidateConnectionAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return await Task.Run(
- () =>
- {
- try
- {
- // Try to read current brightness to validate connection
- using var connection = new WmiConnection(WmiNamespace);
- var query = $"SELECT CurrentBrightness FROM {BrightnessQueryClass} WHERE InstanceName='{monitor.InstanceName}'";
- var results = connection.CreateQuery(query).ToList();
- return results.Count > 0;
- }
- catch (Exception ex)
- {
- Logger.LogWarning($"WMI ValidateConnection failed for {monitor.InstanceName}: {ex.Message}");
- return false;
- }
- },
- cancellationToken);
- }
-
///
/// Get user-friendly name from WMI object
///
@@ -348,69 +323,12 @@ namespace PowerDisplay.Common.Drivers.WMI
}
}
- ///
- /// Check if administrator privileges are required
- ///
- public static bool RequiresElevation()
- {
- try
- {
- using var connection = new WmiConnection(WmiNamespace);
- var query = $"SELECT * FROM {BrightnessMethodClass}";
- var results = connection.CreateQuery(query).ToList();
-
- foreach (var obj in results)
- {
- // Try to call method to check permissions
- try
- {
- using (WmiMethod method = obj.GetMethod("WmiSetBrightness"))
- using (WmiMethodParameters inParams = method.CreateInParameters())
- {
- inParams.SetPropertyValue("Timeout", "0");
- inParams.SetPropertyValue("Brightness", "50");
- obj.ExecuteMethod(method, inParams, out WmiMethodParameters outParams);
- return false; // If successful, no elevation required
- }
- }
- catch (UnauthorizedAccessException)
- {
- return true; // Administrator privileges required
- }
- catch (Exception ex)
- {
- // Other errors may not be permission issues
- Logger.LogDebug($"WMI RequiresElevation check error: {ex.Message}");
- return false;
- }
- }
- }
- catch (Exception ex)
- {
- // Cannot determine, assume privileges required
- Logger.LogWarning($"WMI RequiresElevation check failed: {ex.Message}");
- return true;
- }
-
- return false;
- }
-
// Extended features not supported by WMI
- public Task GetContrastAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return Task.FromResult(BrightnessInfo.Invalid);
- }
-
public Task SetContrastAsync(Monitor monitor, int contrast, CancellationToken cancellationToken = default)
{
return Task.FromResult(MonitorOperationResult.Failure("Contrast control not supported via WMI"));
}
- public Task GetVolumeAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return Task.FromResult(BrightnessInfo.Invalid);
- }
-
public Task SetVolumeAsync(Monitor monitor, int volume, CancellationToken cancellationToken = default)
{
return Task.FromResult(MonitorOperationResult.Failure("Volume control not supported via WMI"));
@@ -443,11 +361,6 @@ namespace PowerDisplay.Common.Drivers.WMI
return Task.FromResult(string.Empty);
}
- public Task SaveCurrentSettingsAsync(Monitor monitor, CancellationToken cancellationToken = default)
- {
- return Task.FromResult(MonitorOperationResult.Failure("Save settings not supported via WMI"));
- }
-
public void Dispose()
{
Dispose(true);
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Interfaces/IMonitorController.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Interfaces/IMonitorController.cs
index 34ca41939b..234345901c 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Interfaces/IMonitorController.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Interfaces/IMonitorController.cs
@@ -53,22 +53,6 @@ namespace PowerDisplay.Common.Interfaces
/// List of monitors
Task> DiscoverMonitorsAsync(CancellationToken cancellationToken = default);
- ///
- /// Validates monitor connection status
- ///
- /// Monitor object
- /// Cancellation token
- /// Whether the monitor is connected
- Task ValidateConnectionAsync(Monitor monitor, CancellationToken cancellationToken = default);
-
- ///
- /// Gets monitor contrast
- ///
- /// Monitor object
- /// Cancellation token
- /// Contrast information
- Task GetContrastAsync(Monitor monitor, CancellationToken cancellationToken = default);
-
///
/// Sets monitor contrast
///
@@ -78,14 +62,6 @@ namespace PowerDisplay.Common.Interfaces
/// Operation result
Task SetContrastAsync(Monitor monitor, int contrast, CancellationToken cancellationToken = default);
- ///
- /// Gets monitor volume
- ///
- /// Monitor object
- /// Cancellation token
- /// Volume information
- Task GetVolumeAsync(Monitor monitor, CancellationToken cancellationToken = default);
-
///
/// Sets monitor volume
///
@@ -137,14 +113,6 @@ namespace PowerDisplay.Common.Interfaces
/// Capabilities string
Task GetCapabilitiesStringAsync(Monitor monitor, CancellationToken cancellationToken = default);
- ///
- /// Saves current settings to monitor
- ///
- /// Monitor object
- /// Cancellation token
- /// Operation result
- Task SaveCurrentSettingsAsync(Monitor monitor, CancellationToken cancellationToken = default);
-
///
/// Releases resources
///
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Services/LightSwitchListener.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Services/LightSwitchListener.cs
index 247c652dd9..e2ac0f5e3e 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Services/LightSwitchListener.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Services/LightSwitchListener.cs
@@ -106,7 +106,7 @@ namespace PowerDisplay.Common.Services
Logger.LogInfo($"{LogPrefix} Theme change event received");
// Process the theme change
- _ = Task.Run(() => ProcessThemeChangeAsync(), CancellationToken.None);
+ _ = Task.Run(() => ProcessThemeChange(), CancellationToken.None);
}
}
@@ -118,7 +118,7 @@ namespace PowerDisplay.Common.Services
}
}
- private async Task ProcessThemeChangeAsync()
+ private void ProcessThemeChange()
{
try
{
@@ -149,8 +149,6 @@ namespace PowerDisplay.Common.Services
{
Logger.LogError($"{LogPrefix} Failed to process theme change: {ex.Message}");
}
-
- await Task.CompletedTask;
}
///
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs
index d4be41a56e..4a32953e5e 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/MonitorFeatureHelper.cs
@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
-using ManagedCommon;
using PowerDisplay.Common.Drivers;
namespace PowerDisplay.Common.Utils
@@ -74,7 +73,7 @@ namespace PowerDisplay.Common.Utils
/// Parse VCP codes from string list to integer set
/// Handles both hex formats: "0x10" and "10"
///
- public static HashSet ParseVcpCodesToIntegers(IReadOnlyList? vcpCodes)
+ private static HashSet ParseVcpCodesToIntegers(IReadOnlyList? vcpCodes)
{
var result = new HashSet();
@@ -105,22 +104,5 @@ namespace PowerDisplay.Common.Utils
return result;
}
-
- ///
- /// Check if a specific VCP code is supported
- ///
- public static bool SupportsVcpCode(IReadOnlyList? vcpCodes, int vcpCode)
- {
- var parsed = ParseVcpCodesToIntegers(vcpCodes);
- return parsed.Contains(vcpCode);
- }
-
- ///
- /// Format VCP code for display (e.g., 0x10 -> "0x10")
- ///
- public static string FormatVcpCode(int vcpCode)
- {
- return $"0x{vcpCode:X2}";
- }
}
}
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/RetryHelper.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/RetryHelper.cs
index c2bf549aee..193ce87e5a 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/RetryHelper.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/RetryHelper.cs
@@ -4,7 +4,6 @@
using System;
using System.Threading;
-using System.Threading.Tasks;
using ManagedCommon;
namespace PowerDisplay.Common.Utils
@@ -25,86 +24,6 @@ namespace PowerDisplay.Common.Utils
///
public const int DefaultMaxRetries = 3;
- ///
- /// Executes an async operation with retry logic.
- ///
- /// The return type of the operation.
- /// The async operation to execute.
- /// Predicate to determine if the result is valid.
- /// Maximum number of retry attempts (default: 3).
- /// Delay between retries in milliseconds (default: 100).
- /// Optional name for logging purposes.
- /// Cancellation token.
- /// The result of the operation, or default if all retries failed.
- public static async Task ExecuteWithRetryAsync(
- Func> operation,
- Func isValid,
- int maxRetries = DefaultMaxRetries,
- int delayMs = DefaultRetryDelayMs,
- string? operationName = null,
- CancellationToken cancellationToken = default)
- {
- for (int attempt = 0; attempt < maxRetries; attempt++)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- try
- {
- var result = await operation();
-
- if (isValid(result))
- {
- if (attempt > 0 && !string.IsNullOrEmpty(operationName))
- {
- Logger.LogDebug($"[Retry] {operationName} succeeded on attempt {attempt + 1}");
- }
-
- return result;
- }
-
- if (attempt < maxRetries - 1)
- {
- if (!string.IsNullOrEmpty(operationName))
- {
- Logger.LogWarning($"[Retry] {operationName} returned invalid result on attempt {attempt + 1}, retrying...");
- }
-
- await Task.Delay(delayMs, cancellationToken);
- }
- }
- catch (OperationCanceledException)
- {
- throw;
- }
- catch (Exception ex)
- {
- if (attempt < maxRetries - 1)
- {
- if (!string.IsNullOrEmpty(operationName))
- {
- Logger.LogWarning($"[Retry] {operationName} failed on attempt {attempt + 1}: {ex.Message}, retrying...");
- }
-
- await Task.Delay(delayMs, cancellationToken);
- }
- else
- {
- if (!string.IsNullOrEmpty(operationName))
- {
- Logger.LogWarning($"[Retry] {operationName} failed after {maxRetries} attempts: {ex.Message}");
- }
- }
- }
- }
-
- if (!string.IsNullOrEmpty(operationName))
- {
- Logger.LogWarning($"[Retry] {operationName} failed after {maxRetries} attempts");
- }
-
- return default;
- }
-
///
/// Executes a synchronous operation with retry logic.
///
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpCodeNames.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpCodeNames.cs
index d976ad29cd..ca9971eea0 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpCodeNames.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpCodeNames.cs
@@ -225,15 +225,5 @@ namespace PowerDisplay.Common.Utils
{
return CodeNames.TryGetValue(code, out var name) ? name : $"Unknown (0x{code:X2})";
}
-
- ///
- /// Check if a VCP code has a known name
- ///
- public static bool HasName(byte code) => CodeNames.ContainsKey(code);
-
- ///
- /// Get all known VCP codes
- ///
- public static IEnumerable GetAllKnownCodes() => CodeNames.Keys;
}
}
diff --git a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpValueNames.cs b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpValueNames.cs
index 261d6711ae..55f3ab3a81 100644
--- a/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpValueNames.cs
+++ b/src/modules/powerdisplay/PowerDisplay.Lib/Utils/VcpValueNames.cs
@@ -188,12 +188,5 @@ namespace PowerDisplay.Common.Utils
return $"0x{value:X2}";
}
-
- ///
- /// Check if a VCP code has value name mappings
- ///
- /// VCP code to check
- /// True if value names are available
- public static bool HasValueNames(byte vcpCode) => ValueNames.ContainsKey(vcpCode);
}
}
diff --git a/src/modules/powerdisplay/PowerDisplay/Commands/RelayCommand.cs b/src/modules/powerdisplay/PowerDisplay/Commands/RelayCommand.cs
index 66abb1a297..84165145d3 100644
--- a/src/modules/powerdisplay/PowerDisplay/Commands/RelayCommand.cs
+++ b/src/modules/powerdisplay/PowerDisplay/Commands/RelayCommand.cs
@@ -53,8 +53,6 @@ namespace PowerDisplay.Commands
Logger.LogError($"Command execution failed: {ex.Message}");
}
}
-
- public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
///
@@ -103,7 +101,5 @@ namespace PowerDisplay.Commands
Logger.LogError($"Command execution failed: {ex.Message}");
}
}
-
- public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
diff --git a/src/modules/powerdisplay/PowerDisplay/Core/MonitorManager.cs b/src/modules/powerdisplay/PowerDisplay/Core/MonitorManager.cs
index 23d6f910a3..d005755978 100644
--- a/src/modules/powerdisplay/PowerDisplay/Core/MonitorManager.cs
+++ b/src/modules/powerdisplay/PowerDisplay/Core/MonitorManager.cs
@@ -356,45 +356,13 @@ namespace PowerDisplay.Core
///
/// Set brightness of the specified monitor
///
- public async Task SetBrightnessAsync(string monitorId, int brightness, CancellationToken cancellationToken = default)
- {
- var monitor = GetMonitor(monitorId);
- if (monitor == null)
- {
- Logger.LogError($"Monitor not found: {monitorId}");
- return MonitorOperationResult.Failure("Monitor not found");
- }
-
- var controller = await GetControllerForMonitorAsync(monitor, cancellationToken);
- if (controller == null)
- {
- Logger.LogError($"No controller available for monitor {monitorId}");
- return MonitorOperationResult.Failure("No controller available for this monitor");
- }
-
- try
- {
- var result = await controller.SetBrightnessAsync(monitor, brightness, cancellationToken);
-
- if (result.IsSuccess)
- {
- // Update monitor status
- monitor.UpdateStatus(brightness, true);
- }
- else
- {
- // If setting fails, monitor may be unavailable
- monitor.IsAvailable = false;
- }
-
- return result;
- }
- catch (Exception ex)
- {
- monitor.IsAvailable = false;
- return MonitorOperationResult.Failure($"Exception setting brightness: {ex.Message}");
- }
- }
+ public Task SetBrightnessAsync(string monitorId, int brightness, CancellationToken cancellationToken = default)
+ => ExecuteMonitorOperationAsync(
+ monitorId,
+ brightness,
+ (ctrl, mon, val, ct) => ctrl.SetBrightnessAsync(mon, val, ct),
+ (mon, val) => mon.UpdateStatus(val, true),
+ cancellationToken);
///
/// Set brightness of all monitors
diff --git a/src/modules/powerdisplay/PowerDisplay/ViewModels/MonitorViewModel.cs b/src/modules/powerdisplay/PowerDisplay/ViewModels/MonitorViewModel.cs
index cf1d2b8b36..cd398f8549 100644
--- a/src/modules/powerdisplay/PowerDisplay/ViewModels/MonitorViewModel.cs
+++ b/src/modules/powerdisplay/PowerDisplay/ViewModels/MonitorViewModel.cs
@@ -275,22 +275,9 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
public int MonitorNumber => _monitor.MonitorNumber;
///
- /// Gets the display name - includes monitor number when multiple monitors are visible
+ /// Gets the display name
///
- public string DisplayName
- {
- get
- {
- // Check if there's more than one visible monitor and MonitorNumber is valid
- // Set the limit to zero for debugging.
- /* if (_mainViewModel != null && _mainViewModel.Monitors.Count > 0 && MonitorNumber > 0)
- {
- return $"{Name} {MonitorNumber}";
- } */
-
- return Name;
- }
- }
+ public string DisplayName => Name;
public string Manufacturer => _monitor.Manufacturer;
@@ -573,12 +560,6 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
-
- // Notify percentage properties when actual values change
- if (propertyName == nameof(Contrast))
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ContrastPercent)));
- }
}
private void OnMainViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e)