Skip to content

feat(settings): add validation for volume and brightness (#42)#61

Open
VIDYANKSHINI wants to merge 1 commit into
DotDev262:mainfrom
VIDYANKSHINI:feature/settings-validation
Open

feat(settings): add validation for volume and brightness (#42)#61
VIDYANKSHINI wants to merge 1 commit into
DotDev262:mainfrom
VIDYANKSHINI:feature/settings-validation

Conversation

@VIDYANKSHINI
Copy link
Copy Markdown

@VIDYANKSHINI VIDYANKSHINI commented May 18, 2026

Related Issue

Closes #42

Proposed Changes

  • Added bounds validation (0 to 100) and format parsing for both volume and brightness settings in SystemSettingsService.cs.
  • Integrated warning logging using the dependency-injected ILogger service for invalid/out-of-range settings.
  • Modernized old console warnings in GetTweaksAsync to use ILogger.LogWarning.
  • Added comprehensive unit tests in SystemSettingsServiceTests.cs covering valid boundaries (0, 100), out-of-range values (-1, 101), and invalid format inputs (like strings and decimals).

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 📖 Documentation
  • 🧪 Testing
  • 🛠️ Refactoring
  • 🚀 DevOps/CI

Testing & Verification

  • I have run dotnet test and all 60+ cross-platform tests passed.
  • I have verified the changes on a Windows environment.
  • I have added new unit tests to cover my changes.

GSSOC 2026 Checklist

  • I have read the Contribution Guidelines.
  • My code is formatted correctly (I have run dotnet format).
  • I have linked the PR to an approved issue.
  • I understand that a maintainer must apply the gssoc:approved label for this PR to count for points.

Copilot AI review requested due to automatic review settings May 18, 2026 11:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds input validation and warning logging around non-registry system settings so invalid brightness/volume values are rejected (with logs) rather than being applied, aligning with the bounds requirements in Issue #42.

Changes:

  • Injected ILogger into SystemSettingsService and replaced Console.WriteLine warnings with ILogger.LogWarning.
  • Added bounds checking (0–100) and invalid-format handling for brightness and volume in ApplyNonRegistrySettingsAsync.
  • Added unit tests covering valid bounds, out-of-range values, and invalid formats for brightness/volume.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Services/System/SystemSettingsService.cs Adds logger integration and validates brightness/volume before issuing PowerShell commands.
tests/WinHome.Tests/SystemSettingsServiceTests.cs Adds tests for new validation and warning-logging behavior.
Comments suppressed due to low confidence (1)

src/Services/System/SystemSettingsService.cs:215

  • userSetting.Value.ToString() will throw if the config contains an explicit null for volume. Since Configuration.SystemSettings is a Dictionary<string, object> populated from YAML/JSON, null values are possible and should be handled by logging an invalid-format warning instead of throwing (use a null-safe conversion).
                    case "volume":
                        if (int.TryParse(userSetting.Value.ToString(), out int volume))
                        {
                            if (volume < 0 || volume > 100)
                            {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +80 to +84
[Theory]
[InlineData(0)]
[InlineData(100)]
[InlineData(50)]
public async Task ApplyNonRegistrySettingsAsync_Should_Accept_Valid_Brightness_Boundaries(int brightness)
Comment on lines 193 to +197
case "brightness":
if (int.TryParse(userSetting.Value.ToString(), out int brightness))
{
string command = $"(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, {brightness})";
_processRunner.RunCommand("powershell", $"-Command \"{command}\"", dryRun);
if (brightness < 0 || brightness > 100)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Settings] Add Validation for Volume and Brightness

2 participants