Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

fix(customize): read the Windows default when a toggle value is unset

fatDuck542d9b0a70e3
diff --git a/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs b/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs
index 1fa00b5..6edca1e 100644
--- a/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs
+++ b/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs
@@ -541,6 +541,54 @@ public class BaseCustomizeSettingTests : IDisposable
Assert.False(toggle.GetState());
}
+ [Fact]
+ public void RegistryToggle_GetState_ReturnsTrueWhenValueAbsentAndDefaultValueIsOn()
+ {
+ // Windows states only what differs from its own default, so an absent value is the
+ // declared default, not "off".
+ var toggle = new RegistryToggle
+ {
+ Path = TestKeyPath,
+ Name = "MissingDefaultOnTest",
+ OnValues = [0],
+ OffValues = [1],
+ DefaultValue = 0,
+ };
+
+ Assert.True(toggle.GetState());
+ }
+
+ [Fact]
+ public void RegistryToggle_GetState_ReturnsFalseWhenValueAbsentAndDefaultValueIsOff()
+ {
+ var toggle = new RegistryToggle
+ {
+ Path = TestKeyPath,
+ Name = "MissingDefaultOffTest",
+ OnValues = [0],
+ OffValues = [1],
+ DefaultValue = 1,
+ };
+
+ Assert.False(toggle.GetState());
+ }
+
+ [Fact]
+ public void RegistryToggle_GetState_KeyAbsentPrefersNullEntryOverDefaultValue()
+ {
+ // An explicit null entry already states the absent case, so it wins over the default.
+ var toggle = new RegistryToggle
+ {
+ Path = TestKeyPath,
+ Name = "MissingNullWinsTest",
+ OnValues = [1],
+ OffValues = [0, null],
+ DefaultValue = 1,
+ };
+
+ Assert.False(toggle.GetState());
+ }
+
[Fact]
public void RegistryToggle_SetState_WritesFirstValueFromList()
{
diff --git a/optimizerDuck/Domain/Customize/Categories/Desktop.cs b/optimizerDuck/Domain/Customize/Categories/Desktop.cs
index e4b2f83..83ea34a 100644
--- a/optimizerDuck/Domain/Customize/Categories/Desktop.cs
+++ b/optimizerDuck/Domain/Customize/Categories/Desktop.cs
@@ -43,7 +43,9 @@ public class Desktop : LocalizedObject, ICustomizeCategory
Name = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
OnValues = [0],
OffValues = [1],
- DefaultValue = 0,
+ // Windows states only the icons it hides, and it never placed This PC on
+ // the desktop by default, so an absent value means hidden.
+ DefaultValue = 1,
},
];
}
diff --git a/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs b/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs
index 6066b21..b29fd82 100644
--- a/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs
+++ b/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs
@@ -33,8 +33,9 @@ public class RegistryToggle
public IReadOnlyList<object?> OffValues { get; init; } = [0];
/// <summary>
- /// Gets the default state value when the key is missing. Used for Reset to Default.
- /// Default is <c>0</c>.
+ /// Gets the value that decides the state when the value is absent from the registry.
+ /// Windows stores only what differs from its own default, so an absent value is the
+ /// default, not "off". Default is <c>0</c>.
/// </summary>
public object? DefaultValue { get; init; } = 0;
@@ -50,10 +51,25 @@ public class RegistryToggle
/// <summary>
/// Reads the registry and returns whether the toggle is currently on. The result is
/// <see langword="true" /> when the value matches any entry in <see cref="OnValues" />.
+ /// An absent value is classified through <see cref="DefaultValue" />; a
+ /// <see langword="null" /> entry in either list states the absent case itself and wins
+ /// over that default.
/// </summary>
public bool GetState()
{
var value = GetRawValue();
+
+ if (value is null)
+ {
+ if (IsValueInList(null, OnValues))
+ return true;
+
+ if (IsValueInList(null, OffValues))
+ return false;
+
+ value = DefaultValue;
+ }
+
return IsValueInList(value, OnValues);
}