Skip to content

[Repo Assist] improve: clamp Brightness/ColorTemperature ranges inside AppSettings.Load() #153

Closed as not planned

Description

@github-actions

🤖 This pull request was created by Repo Assist, an automated AI assistant.

Motivation

AppSettings.Load() had a // Validate deserialized settings comment but did nothing with it. The actual range-clamping was scattered in MainWindow.xaml.cs, which had to know that Brightness ∈ [0.2, 1.0] and ColorTemperature ∈ [0.0, 1.0]. This violated the principle that a type should enforce its own invariants.

Change

  • Added a private ClampRanges() method to AppSettings that calls Math.Clamp() on both numeric settings
  • Called ClampRanges() inside Load() immediately after deserialization, replacing the hollow comment
  • Simplified MainWindow's startup code: removed the Math.Max/Min guards and the "save back if clamped" block — these are now unnecessary because AppSettings.Load() always returns values already in range

Trade-offs

  • Better encapsulation: the valid range of each setting is now expressed exactly once, inside AppSettings
  • No behaviour change for valid settings files; corrupt/out-of-range values are now clamped by AppSettings rather than MainWindow
  • Net diff: AppSettings +12 lines, MainWindow −12 lines

Test Status

Step Result
dotnet build /p:EnableWindowsTargeting=true ✅ 0 errors, 0 warnings

Changes

  • WindowsEdgeLight/AppSettings.cs — add ClampRanges(); call it in Load()
  • WindowsEdgeLight/MainWindow.xaml.cs — remove redundant clamping + save-back block

Note

🔒 Integrity filter blocked 2 items

The following items were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Repo Assist · ● 3.2M · ◷

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch repo-assist/improve-appsettings-validation-2026-07-31-f75beac3fad46f4b.

Click here to create the pull request

To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (92 of 92 lines)
From ce7c05ef8784abd9cbca286f3dad57fa5a851de3 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 31 Jul 2026 13:22:54 +0000
Subject: [PATCH] improve: clamp Brightness/ColorTemperature in
 AppSettings.Load()

AppSettings.Load() had a 'Validate deserialized settings' comment but
no actual validation. Brightness and ColorTemperature were silently
clamped by MainWindow after the fact, with a save-back pass if any
clamping occurred.

Improvement:
- Add private ClampRanges() to AppSettings that calls Math.Clamp() for
  Brightness [0.2, 1.0] and ColorTemperature [0.0, 1.0]
- Call ClampRanges() inside Load() immediately after deserialization
- Simplify MainWindow startup: remove the redundant Math.Max/Min guards
  and the save-back-if-clamped block, as the values are now guaranteed
  in range before they arrive in MainWindow

This keeps the valid-range knowledge inside AppSettings, reducing
coupling and making the Load/MainWindow contract cleaner.

Build: 0 errors, 0 warnings (net10.0-windows, EnableWindowsTargeting=true)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 WindowsEdgeLight/AppSettings.cs     | 12 +++++++++++-
 WindowsEdgeLight/MainWindow.xaml.cs | 14 +++-----------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/WindowsEdgeLight/AppSettings.cs b/WindowsEdgeLight/AppSettings.cs
index 1f46de9..ec5a7a6 100644
--- a/WindowsEdgeLight/AppSettings.cs
+++ b/WindowsEdgeLight/AppSettings.cs
@@ -73,9 +73,9 @@ public class AppSettings
                 };
                 var settings = JsonSerializer.Deserialize<AppSettings>(json, options);
                 
-                // Validate deserialized settings
                 if (settings != null)
                 {
+                    settings.ClampRanges();
                     return settings;
                 }
             }
@@ -101,6 +101,16 @@ public class AppSettings
         return new AppSettings();
     }
 
+
... (truncated)

Activity

  1. shanselman commented on Aug 8, 2026

    @shanselman
    Owner

    Values are already clamped and repaired at application startup; relocating that logic is not a significant user improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions