Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
feat: enhance Customize dropdown architecture with MatchValues and multi-registry bindings
fatDucka496881476b6
diff --git a/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs b/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.csindex 62e1fa3..76a9b68 100644--- a/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs+++ b/optimizerDuck.Test/Domain/Customize/BaseCustomizeSettingTests.cs@@ -1063,5 +1063,80 @@ public class BaseCustomizeSettingTests : IDisposableAssert.Equal("custom", setting.CurrentValue);}+ private class TestMatchMissingDropdown : BaseCustomizeSetting+ {+ public override CustomizeControlType ControlType => CustomizeControlType.Dropdown;++ protected override IReadOnlyList<SettingOption>? GetOptions() =>+ [+ Option("Center", TestKeyPath, "AlignTestKey", 1, matchMissingAsDefault: true),+ Option("Left", TestKeyPath, "AlignTestKey", 0),+ ];+ }++ [Fact]+ public void Dropdown_MatchMissingAsDefault_MatchesWhenKeyAbsent()+ {+ var setting = new TestMatchMissingDropdown { OwnerType = typeof(TestMatchMissingDropdown) };++ // Ensure key is deleted (absent)+ RegistryService.DeleteValue(new RegistryItem(TestKeyPath, "AlignTestKey"));++ // Must match "Center" (value 1) without creating synthetic "Not set" fallback+ Assert.Equal(1, setting.CurrentValue);+ Assert.Equal(2, setting.Options?.Count);++ CleanupTestKeys();+ }++ private class TestMultiBindingWithDefaultDropdown : BaseCustomizeSetting+ {+ private const string RegPathA = @"HKCU\Software\TestOptimizerDuckCustomize";+ private const string RegPathB = @"HKCU\Software\TestOptimizerDuckMultiKey";++ public override CustomizeControlType ControlType => CustomizeControlType.Dropdown;++ protected override IReadOnlyList<SettingOption>? GetOptions() =>+ [+ Option(+ "Always",+ 0,+ BindWithDefault(RegPathA, "Glom1", 0),+ BindWithDefault(RegPathB, "Glom2", 0)+ ),+ Option("WhenFull", 1, Bind(RegPathA, "Glom1", 1), Bind(RegPathB, "Glom2", 1)),+ Option("Never", 2, Bind(RegPathA, "Glom1", 2), Bind(RegPathB, "Glom2", 2)),+ ];+ }++ [Fact]+ public async Task Dropdown_MultiBinding_WithDefault_MatchesWhenKeysAbsent()+ {+ var setting = new TestMultiBindingWithDefaultDropdown+ {+ OwnerType = typeof(TestMultiBindingWithDefaultDropdown),+ };++ // Both absent -> matches Always (0)+ RegistryService.DeleteValue(new RegistryItem(TestKeyPath, "Glom1"));+ RegistryService.DeleteValue(new RegistryItem(@"HKCU\Software\TestOptimizerDuckMultiKey", "Glom2"));++ Assert.Equal(0, setting.CurrentValue);++ // Apply Never (2) -> writes both keys+ await setting.ApplyAsync(2);+ Assert.Equal(2, setting.CurrentValue);+ Assert.Equal(2, RegistryService.Read<int>(new RegistryItem(TestKeyPath, "Glom1")));+ Assert.Equal(2, RegistryService.Read<int>(new RegistryItem(@"HKCU\Software\TestOptimizerDuckMultiKey", "Glom2")));++ CleanupTestKeys();+ try+ {+ using var hkcu = Microsoft.Win32.Registry.CurrentUser;+ hkcu.DeleteSubKeyTree(@"Software\TestOptimizerDuckMultiKey", false);+ }+ catch { }+ }+#endregion}diff --git a/optimizerDuck/Domain/Customize/Categories/Preferences.cs b/optimizerDuck/Domain/Customize/Categories/Preferences.csindex 79e67b1..70e9c2e 100644--- a/optimizerDuck/Domain/Customize/Categories/Preferences.cs+++ b/optimizerDuck/Domain/Customize/Categories/Preferences.cs@@ -44,7 +44,46 @@ public class Preferences : ICustomizeCategorypublic override CustomizeControlType ControlType => CustomizeControlType.Dropdown;protected override IReadOnlyList<SettingOption>? GetOptions() =>- [Option("Center", RegPath, RegName, 1), Option("Left", RegPath, RegName, 0)];+ [+ Option("Center", RegPath, RegName, 1, matchMissingAsDefault: true),+ Option("Left", RegPath, RegName, 0),+ ];+ protected override CustomizeRefreshScope RefreshScope =>+ CustomizeRefreshScope.TaskbarSettings;+ }+ [CustomizeSetting(+ Section = nameof(Sections.Taskbar),+ Icon = SymbolRegular.AppGeneric24,+ Condition = typeof(Windows11Condition)+ )]+ public class CombineTaskbarButtons : BaseCustomizeSetting+ {+ private const string RegPath =+ @"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced";++ public override CustomizeControlType ControlType => CustomizeControlType.Dropdown;++ protected override IReadOnlyList<SettingOption>? GetOptions() =>+ [+ Option(+ "Always",+ 0,+ BindWithDefault(RegPath, "TaskbarGlomLevel", 0),+ BindWithDefault(RegPath, "MMTaskbarGlomLevel", 0)+ ),+ Option(+ "WhenFull",+ 1,+ Bind(RegPath, "TaskbarGlomLevel", 1),+ Bind(RegPath, "MMTaskbarGlomLevel", 1)+ ),+ Option(+ "Never",+ 2,+ Bind(RegPath, "TaskbarGlomLevel", 2),+ Bind(RegPath, "MMTaskbarGlomLevel", 2)+ ),+ ];protected override CustomizeRefreshScope RefreshScope =>CustomizeRefreshScope.TaskbarSettings;diff --git a/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs b/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.csindex 80bbb86..ad2a088 100644--- a/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs+++ b/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs@@ -309,6 +309,27 @@ public abstract partial class BaseCustomizeSetting : ObservableObject, ICustomiz[new RegistryBinding(regPath, regName, value)]);+ protected SettingOption Option(+ string optionKey,+ string regPath,+ string regName,+ object value,+ bool matchMissingAsDefault+ ) =>+ new(+ Loc.Instance[$"Customize.{OwnerKey}.{FeatureKey}.Options.{optionKey}"],+ value,+ [+ new RegistryBinding(+ regPath,+ regName,+ value,+ Microsoft.Win32.RegistryValueKind.DWord,+ matchMissingAsDefault ? [value, null] : null+ ),+ ]+ );+protected SettingOption Option(string optionKey,object value,@@ -320,6 +341,48 @@ public abstract partial class BaseCustomizeSetting : ObservableObject, ICustomizbindings);+ protected RegistryBinding Bind(+ string regPath,+ string? regName,+ object? value,+ params object?[] additionalMatchValues+ ) =>+ new(+ regPath,+ regName,+ value,+ Microsoft.Win32.RegistryValueKind.DWord,+ additionalMatchValues.Length > 0 ? [value, .. additionalMatchValues] : null+ );++ protected RegistryBinding Bind(+ string regPath,+ string? regName,+ object? value,+ Microsoft.Win32.RegistryValueKind valueKind,+ params object?[] additionalMatchValues+ ) =>+ new(+ regPath,+ regName,+ value,+ valueKind,+ additionalMatchValues.Length > 0 ? [value, .. additionalMatchValues] : null+ );++ protected RegistryBinding BindWithDefault(+ string regPath,+ string? regName,+ object value+ ) =>+ new(+ regPath,+ regName,+ value,+ Microsoft.Win32.RegistryValueKind.DWord,+ [value, null]+ );+protected string RecommendationPrefix => $"Customize.{OwnerKey}.{FeatureKey}.Recommendation";/// <summary>@@ -335,7 +398,7 @@ public abstract partial class BaseCustomizeSetting : ObservableObject, ICustomizreturn new CustomizeRecommendationResult(state, $"{RecommendationPrefix}.Reason");}- private static bool ValuesEqual(object? a, object? b)+ public static bool ValuesEqual(object? a, object? b){if (a == null && b == null)return true;@@ -415,7 +478,7 @@ public abstract partial class BaseCustomizeSetting : ObservableObject, ICustomizvar allMatch = option.Bindings.All(b =>{var actual = RegistryService.Read<object>(new RegistryItem(b.Path, b.Name));- return ValuesEqual(actual, b.Value);+ return b.Matches(actual);});if (allMatch)diff --git a/optimizerDuck/Domain/Customize/Models/RegistryBinding.cs b/optimizerDuck/Domain/Customize/Models/RegistryBinding.csindex 4ebc2ad..83ec837 100644--- a/optimizerDuck/Domain/Customize/Models/RegistryBinding.cs+++ b/optimizerDuck/Domain/Customize/Models/RegistryBinding.cs@@ -6,13 +6,30 @@ namespace optimizerDuck.Domain.Customize.Models;/// <summary>/// Binds a <see cref="SettingOption" /> to one or more registry values./// Used by <see cref="BaseCustomizeSetting" /> to auto-read/write registry for Dropdown settings.+/// Supports matching multiple accepted values (e.g. 1 or null for default values)./// </summary>public record RegistryBinding(string Path,string? Name,object? Value,- RegistryValueKind ValueKind = RegistryValueKind.DWord+ RegistryValueKind ValueKind = RegistryValueKind.DWord,+ IReadOnlyList<object?>? MatchValues = null){+ /// <summary>+ /// Checks whether an actual value read from the registry matches this binding.+ /// When <see cref="MatchValues"/> is declared, any value in the list matches.+ /// Otherwise, the actual value must equal <see cref="Value"/>.+ /// </summary>+ public bool Matches(object? actual)+ {+ if (MatchValues is { Count: > 0 })+ {+ return MatchValues.Any(v => BaseCustomizeSetting.ValuesEqual(actual, v));+ }++ return BaseCustomizeSetting.ValuesEqual(actual, Value);+ }+public RegistryItem ToRegistryItem() => new(Path, Name, Value, ValueKind);}diff --git a/optimizerDuck/Resources/Languages/Translations.resx b/optimizerDuck/Resources/Languages/Translations.resxindex 8757845..8b0f0e3 100644--- a/optimizerDuck/Resources/Languages/Translations.resx+++ b/optimizerDuck/Resources/Languages/Translations.resx@@ -895,6 +895,21 @@<data name="Customize.Preferences.TaskbarAlignment.Options.Left" xml:space="preserve"><value>Left</value></data>+ <data name="Customize.Preferences.CombineTaskbarButtons.Name" xml:space="preserve">+ <value>Combine Taskbar Buttons</value>+ </data>+ <data name="Customize.Preferences.CombineTaskbarButtons.Description" xml:space="preserve">+ <value>Choose when to combine taskbar buttons and hide labels across all displays.</value>+ </data>+ <data name="Customize.Preferences.CombineTaskbarButtons.Options.Always" xml:space="preserve">+ <value>Always</value>+ </data>+ <data name="Customize.Preferences.CombineTaskbarButtons.Options.WhenFull" xml:space="preserve">+ <value>When taskbar is full</value>+ </data>+ <data name="Customize.Preferences.CombineTaskbarButtons.Options.Never" xml:space="preserve">+ <value>Never</value>+ </data><data name="Customize.Preferences.ExplorerCompactMode.Name" xml:space="preserve"><value>Explorer Compact Mode</value></data>