Repository navigation
Description
🤖 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 toAppSettingsthat callsMath.Clamp()on both numeric settings - Called
ClampRanges()insideLoad()immediately after deserialization, replacing the hollow comment - Simplified
MainWindow's startup code: removed theMath.Max/Minguards and the "save back if clamped" block — these are now unnecessary becauseAppSettings.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
AppSettingsrather thanMainWindow - 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— addClampRanges(); call it inLoad()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.
- #144
list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved". - Detect camera is being used by another application and automatically turn on #21
list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
To allow these resources, lower min-integrity in your GitHub frontmatter:
tools:
github:
min-integrity: approved # merged | approved | unapproved | noneGenerated 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.
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
shanselman commentedon Aug 8, 2026
Values are already clamped and repaired at application startup; relocating that logic is not a significant user improvement.