Skip to content

Commit e226e01

Browse files
committed
refactor(features): use neutral toggle naming, format files, and improve MouseAcceleration feature state checks
1 parent 061bff2 commit e226e01

15 files changed

Lines changed: 228 additions & 197 deletions

optimizerDuck/App.xaml.cs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Format(LogEvent logEvent, TextWriter output)
5454
};
5555

5656
//var prefix = $"{timestamp} | {ctx,-67} | {levelText,-7} | "; // byebye 67 char SourceContext truncation, we have a new design now...
57-
var prefix = $"{timestamp} | {ctx,-35} | {levelText,-7} | ";
57+
var prefix = $"{timestamp} | {ctx, -35} | {levelText, -7} | ";
5858

5959
// print message
6060
output.WriteLine(prefix + RenderWithoutQuotes(logEvent));
@@ -318,8 +318,7 @@ protected override void OnExit(ExitEventArgs e)
318318
base.OnExit(e);
319319
}
320320

321-
protected async void MainWindow_Closing(object? sender,
322-
CancelEventArgs e)
321+
protected async void MainWindow_Closing(object? sender, CancelEventArgs e)
323322
{
324323
if (_allowClose)
325324
{
@@ -335,50 +334,38 @@ protected async void MainWindow_Closing(object? sender,
335334

336335
try
337336
{
338-
_contentDialogService ??=
339-
_host!.Services.GetRequiredService<IContentDialogService>();
337+
_contentDialogService ??= _host!.Services.GetRequiredService<IContentDialogService>();
340338

341339
var result = await _contentDialogService.ShowSimpleDialogAsync(
342340
new SimpleContentDialogCreateOptions
343341
{
344342
Title = Translations.Dialog_PendingChanges_Title,
345343
Content = Translations.Dialog_PendingChanges_Content,
346-
CloseButtonText =
347-
Translations.Dialog_PendingChanges_CloseButton,
348-
PrimaryButtonText =
349-
Translations.Dialog_PendingChanges_PrimaryButton,
350-
SecondaryButtonText =
351-
Translations.Dialog_PendingChanges_SecondaryButton
344+
CloseButtonText = Translations.Dialog_PendingChanges_CloseButton,
345+
PrimaryButtonText = Translations.Dialog_PendingChanges_PrimaryButton,
346+
SecondaryButtonText = Translations.Dialog_PendingChanges_SecondaryButton,
352347
}
353348
);
354349

355350
switch (result)
356351
{
357352
case ContentDialogResult.Primary:
358-
_logger.LogInformation(
359-
"User chose to restart PC."
360-
);
353+
_logger.LogInformation("User chose to restart PC.");
361354

362355
ShellService.CMD("shutdown /r /t 0");
363356
break;
364357

365358
case ContentDialogResult.Secondary:
366-
_logger.LogInformation(
367-
"User chose to restart Explorer."
368-
);
359+
_logger.LogInformation("User chose to restart Explorer.");
369360

370-
ShellService.CMD(
371-
"taskkill /f /im explorer.exe && start explorer.exe"
372-
);
361+
ShellService.CMD("taskkill /f /im explorer.exe && start explorer.exe");
373362

374363
_allowClose = true;
375364
Current.Shutdown();
376365
break;
377366

378367
case ContentDialogResult.None:
379-
_logger.LogInformation(
380-
"User chose to exit without applying changes."
381-
);
368+
_logger.LogInformation("User chose to exit without applying changes.");
382369

383370
_allowClose = true;
384371
Current.Shutdown();
@@ -387,10 +374,7 @@ protected async void MainWindow_Closing(object? sender,
387374
}
388375
catch (Exception ex)
389376
{
390-
_logger.LogError(
391-
ex,
392-
"Failed to show pending changes dialog."
393-
);
377+
_logger.LogError(ex, "Failed to show pending changes dialog.");
394378

395379
_allowClose = true;
396380
Current.Shutdown();

optimizerDuck/Domain/Features/Categories/Desktop.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using optimizerDuck.Domain.Abstractions;
33
using optimizerDuck.Domain.Attributes;
44
using optimizerDuck.Domain.Features.Models;
@@ -140,7 +140,7 @@ public class ShowDesktopIcons : BaseFeature
140140
}
141141

142142
[Feature(Section = nameof(Sections.Behaviors), Icon = SymbolRegular.ArrowForward24)]
143-
public class RemoveShortcutArrow : BaseFeature
143+
public class ShortcutArrow : BaseFeature
144144
{
145145
private const string Path =
146146
@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons";
@@ -150,18 +150,13 @@ public class RemoveShortcutArrow : BaseFeature
150150
public override Task<bool> GetStateAsync()
151151
{
152152
var value = RegistryService.Read<string>(new RegistryItem(Path, "29"));
153-
return Task.FromResult(value?.ToString() == @"%windir%\System32\shell32.dll,-50");
153+
return Task.FromResult(string.Equals(value, "", StringComparison.OrdinalIgnoreCase));
154154
}
155155

156156
public override async Task EnableAsync()
157157
{
158158
RegistryService.Write(
159-
new RegistryItem(
160-
Path,
161-
"29",
162-
@"%windir%\System32\shell32.dll,-50",
163-
Microsoft.Win32.RegistryValueKind.String
164-
)
159+
new RegistryItem(Path, "29", @"%windir%\System32\shell32.dll,-50")
165160
);
166161
if (NeedsPostAction)
167162
await ExecutePostActionAsync();

optimizerDuck/Domain/Features/Categories/Gaming.cs

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using optimizerDuck.Domain.Abstractions;
33
using optimizerDuck.Domain.Attributes;
44
using optimizerDuck.Domain.Features.Models;
@@ -142,33 +142,75 @@ public class BackgroundRecording : BaseFeature
142142
[Feature(Section = nameof(Sections.Input), Icon = SymbolRegular.Cursor24)]
143143
public class MouseAcceleration : BaseFeature
144144
{
145-
protected override IEnumerable<RegistryToggle> RegistryToggles =>
146-
[
147-
new()
148-
{
149-
Path = @"HKCU\Control Panel\Mouse",
150-
Name = "MouseSpeed",
151-
OnValue = "0",
152-
OffValue = "1",
153-
DefaultValue = "1",
154-
},
155-
new()
156-
{
157-
Path = @"HKCU\Control Panel\Mouse",
158-
Name = "MouseThreshold1",
159-
OnValue = "0",
160-
OffValue = "6",
161-
DefaultValue = "6",
162-
},
163-
new()
164-
{
165-
Path = @"HKCU\Control Panel\Mouse",
166-
Name = "MouseThreshold2",
167-
OnValue = "0",
168-
OffValue = "10",
169-
DefaultValue = "10",
170-
},
171-
];
145+
private const string Path = @"HKCU\Control Panel\Mouse";
146+
147+
public override Task<bool> GetStateAsync()
148+
{
149+
// Mouse acceleration is ON if any of the values are non-zero
150+
var mouseSpeed = RegistryService.Read<string>(new RegistryItem(Path, "MouseSpeed"));
151+
var threshold1 = RegistryService.Read<string>(
152+
new RegistryItem(Path, "MouseThreshold1")
153+
);
154+
var threshold2 = RegistryService.Read<string>(
155+
new RegistryItem(Path, "MouseThreshold2")
156+
);
157+
158+
// Check if any value is non-zero (acceleration enabled)
159+
var isNonZero =
160+
(int.TryParse(mouseSpeed, out var speed) && speed != 0)
161+
|| (int.TryParse(threshold1, out var t1) && t1 != 0)
162+
|| (int.TryParse(threshold2, out var t2) && t2 != 0);
163+
164+
return Task.FromResult(isNonZero);
165+
}
166+
167+
public override async Task EnableAsync()
168+
{
169+
RegistryService.Write(
170+
new RegistryItem(Path, "MouseSpeed", "1")
171+
);
172+
RegistryService.Write(
173+
new RegistryItem(
174+
Path,
175+
"MouseThreshold1",
176+
"6"
177+
)
178+
);
179+
RegistryService.Write(
180+
new RegistryItem(
181+
Path,
182+
"MouseThreshold2",
183+
"10"
184+
)
185+
);
186+
187+
if (NeedsPostAction)
188+
await ExecutePostActionAsync();
189+
}
190+
191+
public override async Task DisableAsync()
192+
{
193+
RegistryService.Write(
194+
new RegistryItem(Path, "MouseSpeed", "0")
195+
);
196+
RegistryService.Write(
197+
new RegistryItem(
198+
Path,
199+
"MouseThreshold1",
200+
"0"
201+
)
202+
);
203+
RegistryService.Write(
204+
new RegistryItem(
205+
Path,
206+
"MouseThreshold2",
207+
"0"
208+
)
209+
);
210+
211+
if (NeedsPostAction)
212+
await ExecutePostActionAsync();
213+
}
172214
}
173215

174216
[Feature(Section = nameof(Sections.Display), Icon = SymbolRegular.FullScreenMaximize24)]

optimizerDuck/Domain/Features/Categories/Preferences.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using optimizerDuck.Domain.Abstractions;
33
using optimizerDuck.Domain.Attributes;
44
using optimizerDuck.Domain.Features.Models;
@@ -121,17 +121,15 @@ public class DarkMode : BaseFeature
121121
[
122122
new()
123123
{
124-
Path =
125-
@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
124+
Path = @"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
126125
Name = "AppsUseLightTheme",
127126
OnValue = 0,
128127
OffValue = 1,
129128
DefaultValue = 1,
130129
},
131130
new()
132131
{
133-
Path =
134-
@"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
132+
Path = @"HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
135133
Name = "SystemUsesLightTheme",
136134
OnValue = 0,
137135
OffValue = 1,
@@ -355,7 +353,7 @@ public class LaunchToThisPc : BaseFeature
355353
}
356354

357355
[Feature(Section = nameof(Sections.Taskbar), Icon = SymbolRegular.Search24)]
358-
public class DisableBingSearch : BaseFeature
356+
public class BingSearch : BaseFeature
359357
{
360358
protected override bool NeedsPostAction => true;
361359

@@ -365,8 +363,8 @@ public class DisableBingSearch : BaseFeature
365363
{
366364
Path = @"HKCU\Software\Policies\Microsoft\Windows\Explorer",
367365
Name = "DisableSearchBoxSuggestions",
368-
OnValue = 1,
369-
OffValue = 0,
366+
OnValue = 0,
367+
OffValue = 1,
370368
DefaultValue = 0,
371369
},
372370
];

optimizerDuck/Domain/Features/Categories/SystemFeatures.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
22
using optimizerDuck.Domain.Abstractions;
33
using optimizerDuck.Domain.Attributes;
44
using optimizerDuck.Domain.Features.Models;
5-
using optimizerDuck.Domain.Optimizations.Models.Services;
65
using optimizerDuck.Domain.UI;
76
using optimizerDuck.Services.Managers;
87
using optimizerDuck.UI.Pages.Features;
@@ -25,7 +24,7 @@ private enum Sections
2524
public ObservableCollection<IFeature> Features { get; init; } = [];
2625

2726
[Feature(Section = nameof(Sections.Input), Icon = SymbolRegular.NumberSymbol24)]
28-
public class EnableNumLockOnBoot : BaseFeature
27+
public class NumLockOnBoot : BaseFeature
2928
{
3029
protected override IEnumerable<RegistryToggle> RegistryToggles =>
3130
[

optimizerDuck/Domain/Features/Models/RegistryToggle.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class RegistryToggle
1717
public bool GetState()
1818
{
1919
var value = GetRawValue();
20-
20+
2121
if (value == null)
2222
{
2323
// If value is null and TreatMissingAsDefault is false,
@@ -50,21 +50,39 @@ private static bool AreEqual(object? a, object? b)
5050
// For numeric types, compare as the most precise type
5151
var typeA = a.GetType();
5252
var typeB = b.GetType();
53-
53+
5454
// If both are integers, compare as long
55-
if ((typeA == typeof(int) || typeA == typeof(long) || typeA == typeof(short) || typeA == typeof(byte)) &&
56-
(typeB == typeof(int) || typeB == typeof(long) || typeB == typeof(short) || typeB == typeof(byte)))
55+
if (
56+
(
57+
typeA == typeof(int)
58+
|| typeA == typeof(long)
59+
|| typeA == typeof(short)
60+
|| typeA == typeof(byte)
61+
)
62+
&& (
63+
typeB == typeof(int)
64+
|| typeB == typeof(long)
65+
|| typeB == typeof(short)
66+
|| typeB == typeof(byte)
67+
)
68+
)
5769
{
5870
return Convert.ToInt64(a) == Convert.ToInt64(b);
5971
}
60-
72+
6173
// For floating point, compare as double
62-
if ((typeA == typeof(float) || typeA == typeof(double) || typeA == typeof(decimal)) &&
63-
(typeB == typeof(float) || typeB == typeof(double) || typeB == typeof(decimal)))
74+
if (
75+
(typeA == typeof(float) || typeA == typeof(double) || typeA == typeof(decimal))
76+
&& (
77+
typeB == typeof(float)
78+
|| typeB == typeof(double)
79+
|| typeB == typeof(decimal)
80+
)
81+
)
6482
{
6583
return Convert.ToDouble(a) == Convert.ToDouble(b);
6684
}
67-
85+
6886
// Fallback to decimal comparison for other convertible types
6987
var da = Convert.ToDecimal(a);
7088
var db = Convert.ToDecimal(b);

0 commit comments

Comments
 (0)