Skip to content

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

feat: add global Smooth Scrolling toggle and improve logging

fatDuck5f5553033365
diff --git a/optimizerDuck.Test/Domain/Revert/Steps/RevertStepSerializationTests.cs b/optimizerDuck.Test/Domain/Revert/Steps/RevertStepSerializationTests.cs
index 119b217..264dbb0 100644
--- a/optimizerDuck.Test/Domain/Revert/Steps/RevertStepSerializationTests.cs
+++ b/optimizerDuck.Test/Domain/Revert/Steps/RevertStepSerializationTests.cs
@@ -43,11 +43,7 @@ public class RevertStepSerializationTests
[Fact]
public void ShellRevertStep_WithEmptyCommand_RoundTrip()
{
- var original = new ShellRevertStep
- {
- ShellType = ShellType.CMD,
- Command = "",
- };
+ var original = new ShellRevertStep { ShellType = ShellType.CMD, Command = "" };
var json = original.ToData();
var restored = ShellRevertStep.FromData(json);
diff --git a/optimizerDuck.Test/Services/OptimizationServiceTests.cs b/optimizerDuck.Test/Services/OptimizationServiceTests.cs
index 6faff9f..cdb6c13 100644
--- a/optimizerDuck.Test/Services/OptimizationServiceTests.cs
+++ b/optimizerDuck.Test/Services/OptimizationServiceTests.cs
@@ -597,8 +597,7 @@ public class OptimizationServiceTests
public Func<
(IProgress<ProcessingProgress> progress, OptimizationContext context),
Task<ApplyResult>
- > ApplyImpl
- { get; init; } = _ => Task.FromResult(ApplyResult.True());
+ > ApplyImpl { get; init; } = _ => Task.FromResult(ApplyResult.True());
public Guid Id { get; } = Guid.NewGuid();
public OptimizationRisk Risk { get; } = OptimizationRisk.Safe;
diff --git a/optimizerDuck/App.xaml.cs b/optimizerDuck/App.xaml.cs
index 586f968..9aa0a0d 100644
--- a/optimizerDuck/App.xaml.cs
+++ b/optimizerDuck/App.xaml.cs
@@ -15,6 +15,7 @@ using optimizerDuck.Resources.Languages;
using optimizerDuck.Services;
using optimizerDuck.Services.Managers;
using optimizerDuck.Services.OptimizationServices;
+using optimizerDuck.UI.Behaviors;
using optimizerDuck.UI.Pages;
using optimizerDuck.UI.ViewModels.Pages;
using optimizerDuck.UI.ViewModels.Windows;
@@ -270,6 +271,8 @@ public partial class App : Application
var appSettings = appOptionsMonitor.CurrentValue;
+ SmoothScrollBehavior.GlobalEnabled = appSettings.Optimize.SmoothScrolling;
+
await Dispatcher.InvokeAsync(() =>
{
Loc.Instance.ChangeCulture(new CultureInfo(appSettings.App.Language));
diff --git a/optimizerDuck/Domain/Configuration/AppSettings.cs b/optimizerDuck/Domain/Configuration/AppSettings.cs
index 0d768e4..d9b2fa2 100644
--- a/optimizerDuck/Domain/Configuration/AppSettings.cs
+++ b/optimizerDuck/Domain/Configuration/AppSettings.cs
@@ -57,6 +57,11 @@ public sealed class AppSettings
/// Whether to show the success snackbar after applying an optimization.
/// </summary>
public bool ShowCompletionNotification { get; set; } = false;
+
+ /// <summary>
+ /// Whether smooth scrolling is enabled globally.
+ /// </summary>
+ public bool SmoothScrolling { get; set; } = true;
}
/// <summary>
diff --git a/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs b/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs
index c3fa119..15f6c07 100644
--- a/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs
+++ b/optimizerDuck/Domain/Revert/Steps/RegistryRevertStep.cs
@@ -104,8 +104,7 @@ public class RegistryRevertStep : IRevertStep
if (!result)
{
- var error = RegistryService.LastError
- ?? Description;
+ var error = RegistryService.LastError ?? Description;
throw new StepExecutionException(error, RegistryService.LastErrorDetail);
}
diff --git a/optimizerDuck/Domain/Revert/Steps/ScheduledTaskRevertStep.cs b/optimizerDuck/Domain/Revert/Steps/ScheduledTaskRevertStep.cs
index 7d7c557..4aa99a6 100644
--- a/optimizerDuck/Domain/Revert/Steps/ScheduledTaskRevertStep.cs
+++ b/optimizerDuck/Domain/Revert/Steps/ScheduledTaskRevertStep.cs
@@ -42,8 +42,7 @@ public class ScheduledTaskRevertStep : IRevertStep
if (!success)
{
- var error = ScheduledTaskService.LastError
- ?? Description;
+ var error = ScheduledTaskService.LastError ?? Description;
throw new StepExecutionException(error, ScheduledTaskService.LastErrorDetail);
}
diff --git a/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs b/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs
index 78edfbb..f0d3723 100644
--- a/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs
+++ b/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs
@@ -42,8 +42,7 @@ public class ServiceRevertStep : IRevertStep
if (!result)
{
- var error = ServiceProcessService.LastError
- ?? Description;
+ var error = ServiceProcessService.LastError ?? Description;
throw new StepExecutionException(error, ServiceProcessService.LastErrorDetail);
}
diff --git a/optimizerDuck/Resources/Languages/Translations.resx b/optimizerDuck/Resources/Languages/Translations.resx
index 2924b80..11419ad 100644
--- a/optimizerDuck/Resources/Languages/Translations.resx
+++ b/optimizerDuck/Resources/Languages/Translations.resx
@@ -496,6 +496,12 @@
<data name="Settings.Advanced.OpenRootDir.Description" xml:space="preserve">
<value>Open the application's root directory, where all necessary files are stored.</value>
</data>
+ <data name="Settings.Appearance.SmoothScrolling.Title" xml:space="preserve">
+ <value>Smooth Scrolling</value>
+ </data>
+ <data name="Settings.Appearance.SmoothScrolling.Description" xml:space="preserve">
+ <value>Enable smooth scrolling animation for a more fluid scrolling experience. Turn off if you experience lag.</value>
+ </data>
<data name="Button.Open" xml:space="preserve">
<value>Open</value>
</data>
diff --git a/optimizerDuck/Resources/Languages/Translations.vi-VN.resx b/optimizerDuck/Resources/Languages/Translations.vi-VN.resx
index 6c21bdb..442029d 100644
--- a/optimizerDuck/Resources/Languages/Translations.vi-VN.resx
+++ b/optimizerDuck/Resources/Languages/Translations.vi-VN.resx
@@ -490,6 +490,12 @@
<data name="Settings.Advanced.OpenRootDir.Description" xml:space="preserve">
<value>Mở thư mục gốc của ứng dụng, nơi chứa tất cả các tệp cần thiết.</value>
</data>
+ <data name="Settings.Appearance.SmoothScrolling.Title" xml:space="preserve">
+ <value>Cuộn mượt</value>
+ </data>
+ <data name="Settings.Appearance.SmoothScrolling.Description" xml:space="preserve">
+ <value>Bật hiệu ứng cuộn mượt để trải nghiệm cuộn mượt mà hơn. Tắt nếu bạn thấy lag.</value>
+ </data>
<data name="Button.Open" xml:space="preserve">
<value>Mở</value>
</data>
diff --git a/optimizerDuck/Resources/Languages/Translations.zh-CN.resx b/optimizerDuck/Resources/Languages/Translations.zh-CN.resx
index 6e6989a..602ee6f 100644
--- a/optimizerDuck/Resources/Languages/Translations.zh-CN.resx
+++ b/optimizerDuck/Resources/Languages/Translations.zh-CN.resx
@@ -241,6 +241,12 @@
<data name="Settings.Appearance.ThemeSelector.HighContrast" xml:space="preserve">
<value>高对比度</value>
</data>
+ <data name="Settings.Appearance.SmoothScrolling.Title" xml:space="preserve">
+ <value>平滑滚动</value>
+ </data>
+ <data name="Settings.Appearance.SmoothScrolling.Description" xml:space="preserve">
+ <value>启用平滑滚动动画,让滚动体验更流畅。如果觉得卡顿请关闭。</value>
+ </data>
<data name="Common.AppliedSecondsAgo" xml:space="preserve">
<value>{0} 秒前应用</value>
</data>
diff --git a/optimizerDuck/Resources/Languages/Translations.zh-TW.resx b/optimizerDuck/Resources/Languages/Translations.zh-TW.resx
index 795c6f1..a4286f8 100644
--- a/optimizerDuck/Resources/Languages/Translations.zh-TW.resx
+++ b/optimizerDuck/Resources/Languages/Translations.zh-TW.resx
@@ -216,6 +216,12 @@
<data name="Settings.Appearance.ThemeSelector.HighContrast" xml:space="preserve">
<value>高對比</value>
</data>
+ <data name="Settings.Appearance.SmoothScrolling.Title" xml:space="preserve">
+ <value>平滑滾動</value>
+ </data>
+ <data name="Settings.Appearance.SmoothScrolling.Description" xml:space="preserve">
+ <value>啟用平滑滾動動畫,讓滾動體驗更流暢。如果覺得卡頓請關閉。</value>
+ </data>
<data name="Common.AppliedSecondsAgo" xml:space="preserve">
<value>{0} 秒前套用</value>
</data>
diff --git a/optimizerDuck/Services/Optimization/Providers/RegistryService.cs b/optimizerDuck/Services/Optimization/Providers/RegistryService.cs
index c7b8ba0..e1a1093 100644
--- a/optimizerDuck/Services/Optimization/Providers/RegistryService.cs
+++ b/optimizerDuck/Services/Optimization/Providers/RegistryService.cs
@@ -513,11 +513,7 @@ public static class RegistryService
{
ExecutionScope.LogInfo("Skip create registry {Path} (already exists)", item.Path);
ExecutionScope.Track(nameof(CreateSubKey), true);
- ExecutionScope.RecordStep(
- Translations.Service_Registry_Name,
- description,
- true
- );
+ ExecutionScope.RecordStep(Translations.Service_Registry_Name, description, true);
return true;
}
diff --git a/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs b/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
index c681e36..e220244 100644
--- a/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
+++ b/optimizerDuck/Services/Optimization/Providers/ServiceProcessService.cs
@@ -131,8 +131,8 @@ public static class ServiceProcessService
return true;
}
- _lastError.Value = regError
- ?? Translations.Service_Service_Error_UpdateRegistryForStartupTypeFailed;
+ _lastError.Value =
+ regError ?? Translations.Service_Service_Error_UpdateRegistryForStartupTypeFailed;
_lastErrorDetail.Value = regErrorDetail;
ExecutionScope.LogInfo(
"[SERVICE][{Name}][FAIL][D={Duration}] startup -> {StartupType}",
@@ -147,7 +147,8 @@ public static class ServiceProcessService
false,
null,
_lastError.Value,
- () => Task.FromResult(ChangeServiceStartupType(item))
+ () => Task.FromResult(ChangeServiceStartupType(item)),
+ _lastErrorDetail.Value
);
return false;
}
@@ -172,7 +173,8 @@ public static class ServiceProcessService
false,
null,
_lastError.Value,
- () => Task.FromResult(ChangeServiceStartupType(item))
+ () => Task.FromResult(ChangeServiceStartupType(item)),
+ _lastErrorDetail.Value
);
return false;
}
diff --git a/optimizerDuck/Services/Optimization/Providers/ShellService.cs b/optimizerDuck/Services/Optimization/Providers/ShellService.cs
index 8a8dea7..24138a1 100644
--- a/optimizerDuck/Services/Optimization/Providers/ShellService.cs
+++ b/optimizerDuck/Services/Optimization/Providers/ShellService.cs
@@ -256,7 +256,8 @@ public static class ShellService
policy.IsSuccess(
Run(fileName, arguments, command, serviceName, revertStep, policy)
)
- )
+ ),
+ success ? null : GetShellErrorDetail(result)
);
return result;
@@ -291,7 +292,8 @@ public static class ShellService
policy.IsSuccess(
Run(fileName, arguments, command, serviceName, revertStep, policy)
)
- )
+ ),
+ ex.ToString()
);
return result;
@@ -502,7 +504,8 @@ public static class ShellService
policy,
ct
)
- )
+ ),
+ success ? null : GetShellErrorDetail(result)
);
return result;
@@ -543,7 +546,8 @@ public static class ShellService
policy,
ct
)
- )
+ ),
+ ex.ToString()
);
return result;
@@ -831,5 +835,35 @@ public static class ShellService
);
}
+ private static string GetShellErrorDetail(ShellResult result)
+ {
+ var sections = new List<string>
+ {
+ $"Command: {result.Command}",
+ $"Exit Code: {result.ExitCode}",
+ $"Duration: {result.Duration.TotalMilliseconds:F0}ms",
+ };
+
+ var details = new List<string>();
+
+ if (!string.IsNullOrWhiteSpace(result.Stdout))
+ {
+ details.Add($"STDOUT:\n{result.Stdout.Trim()}");
+ }
+
+ if (!string.IsNullOrWhiteSpace(result.Stderr))
+ {
+ details.Add($"STDERR:\n{result.Stderr.Trim()}");
+ }
+
+ if (details.Count > 0)
+ {
+ sections.Add(string.Empty);
+ sections.AddRange(details);
+ }
+
+ return string.Join("\n", sections);
+ }
+
#endregion PowerShell methods
}
diff --git a/optimizerDuck/Services/Revert/RevertManager.cs b/optimizerDuck/Services/Revert/RevertManager.cs
index b65d8a9..5c5857c 100644
--- a/optimizerDuck/Services/Revert/RevertManager.cs
+++ b/optimizerDuck/Services/Revert/RevertManager.cs
@@ -267,11 +267,7 @@ public class RevertManager(ILogger<RevertManager> _logger, ILoggerFactory _logge
private static void TraceCorruptRevertFile(string path, Exception ex)
{
- System.Diagnostics.Trace.TraceWarning(
- "Corrupt revert file {0}: {1}",
- path,
- ex.Message
- );
+ System.Diagnostics.Trace.TraceWarning("Corrupt revert file {0}: {1}", path, ex.Message);
}
public void RemoveRevertData(Guid id, string? name = null)
@@ -313,7 +309,11 @@ public class RevertManager(ILogger<RevertManager> _logger, ILoggerFactory _logge
private async Task<SemaphoreSlim> AcquireFileLockAsync(Guid id)
{
var lockObj = _fileLocks.GetOrAdd(id, _ => new SemaphoreSlim(1, 1));
- if (!await lockObj.WaitAsync(TimeSpan.FromSeconds(FileLockTimeoutSeconds)).ConfigureAwait(false))
+ if (
+ !await lockObj
+ .WaitAsync(TimeSpan.FromSeconds(FileLockTimeoutSeconds))
+ .ConfigureAwait(false)
+ )
throw new TimeoutException(
string.Format("Timed out waiting for revert file lock ({0}).", id)
);
@@ -371,7 +371,11 @@ public class RevertManager(ILogger<RevertManager> _logger, ILoggerFactory _logge
if (File.Exists(path))
{
File.Delete(path);
- _logger.LogInformation("Removed revert data for {Name}: {Path}", name ?? id.ToString(), path);
+ _logger.LogInformation(
+ "Removed revert data for {Name}: {Path}",
+ name ?? id.ToString(),
+ path
+ );
}
var tempPath = path + ".tmp";
diff --git a/optimizerDuck/UI/Behaviors/SmoothScrollBehavior.cs b/optimizerDuck/UI/Behaviors/SmoothScrollBehavior.cs
index c62fd2b..08224e1 100644
--- a/optimizerDuck/UI/Behaviors/SmoothScrollBehavior.cs
+++ b/optimizerDuck/UI/Behaviors/SmoothScrollBehavior.cs
@@ -9,6 +9,12 @@ namespace optimizerDuck.UI.Behaviors;
public static class SmoothScrollBehavior
{
+ /// <summary>
+ /// Global toggle for smooth scrolling. When disabled, all smooth scroll
+ /// processing is skipped regardless of per-element IsEnabled.
+ /// </summary>
+ public static bool GlobalEnabled { get; set; } = true;
+
private sealed class ScrollState
{
public double TargetY;
@@ -16,6 +22,12 @@ public static class SmoothScrollBehavior
public bool IsAnimating;
public bool IsAttached;
public long LastScrollTicks;
+ public int RapidScrollCount;
+
+ public double CachedSmoothing = 0.20;
+ public double CachedScrollDelta = 48.0;
+ public double CachedMultiplier = 1.0;
+ public bool PreviousCanContentScroll;
}
private static readonly ConditionalWeakTable<ScrollViewer, ScrollState> _stateTable = new();
@@ -23,31 +35,62 @@ public static class SmoothScrollBehavior
private static bool _renderingSubscribed;
private const double SnapThreshold = 0.5;
+ private const double MaxScrollSpeedPerFrame = 80.0;
+
+ public static readonly DependencyProperty IsEnabledProperty =
+ DependencyProperty.RegisterAttached(
+ "IsEnabled",
+ typeof(bool),
+ typeof(SmoothScrollBehavior),
+ new PropertyMetadata(false, OnIsEnabledChanged)
+ );
+
+ public static readonly DependencyProperty ScrollDeltaProperty =
+ DependencyProperty.RegisterAttached(
+ "ScrollDelta",
+ typeof(double),
+ typeof(SmoothScrollBehavior),
+ new PropertyMetadata(48.0)
+ );
+
+ public static readonly DependencyProperty MultiplierProperty =
+ DependencyProperty.RegisterAttached(
+ "Multiplier",
+ typeof(double),
+ typeof(SmoothScrollBehavior),
+ new PropertyMetadata(1.0)
+ );
+
+ public static readonly DependencyProperty SmoothingProperty =
+ DependencyProperty.RegisterAttached(
+ "Smoothing",
+ typeof(double),
+ typeof(SmoothScrollBehavior),
+ new PropertyMetadata(0.20)
+ );
+
+ public static bool GetIsEnabled(DependencyObject obj) => (bool)obj.GetValue(IsEnabledProperty);
- public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached(
- "IsEnabled", typeof(bool), typeof(SmoothScrollBehavior),
- new PropertyMetadata(false, OnIsEnabledChanged));
+ public static void SetIsEnabled(DependencyObject obj, bool value) =>
+ obj.SetValue(IsEnabledProperty, value);
- public static readonly DependencyProperty ScrollDeltaProperty = DependencyProperty.RegisterAttached(
- "ScrollDelta", typeof(double), typeof(SmoothScrollBehavior),
- new PropertyMetadata(48.0));
+ public static double GetScrollDelta(DependencyObject obj) =>
+ (double)obj.GetValue(ScrollDeltaProperty);
- public static readonly DependencyProperty MultiplierProperty = DependencyProperty.RegisterAttached(
- "Multiplier", typeof(double), typeof(SmoothScrollBehavior),
- new PropertyMetadata(1.0));
+ public static void SetScrollDelta(DependencyObject obj, double value) =>
+ obj.SetValue(ScrollDeltaProperty, value);
- public static readonly DependencyProperty SmoothingProperty = DependencyProperty.RegisterAttached(
- "Smoothing", typeof(double), typeof(SmoothScrollBehavior),
- new PropertyMetadata(0.20));
+ public static double GetMultiplier(DependencyObject obj) =>
+ (double)obj.GetValue(MultiplierProperty);
- public static bool GetIsEnabled(DependencyObject obj) => (bool)obj.GetValue(IsEnabledProperty);
- public static void SetIsEnabled(DependencyObject obj, bool value) => obj.SetValue(IsEnabledProperty, value);
- public static double GetScrollDelta(DependencyObject obj) => (double)obj.GetValue(ScrollDeltaProperty);
- public static void SetScrollDelta(DependencyObject obj, double value) => obj.SetValue(ScrollDeltaProperty, value);
- public static double GetMultiplier(DependencyObject obj) => (double)obj.GetValue(MultiplierProperty);
- public static void SetMultiplier(DependencyObject obj, double value) => obj.SetValue(MultiplierProperty, value);
- public static double GetSmoothing(DependencyObject obj) => (double)obj.GetValue(SmoothingProperty);
- public static void SetSmoothing(DependencyObject obj, double value) => obj.SetValue(SmoothingProperty, value);
+ public static void SetMultiplier(DependencyObject obj, double value) =>
+ obj.SetValue(MultiplierProperty, value);
+
+ public static double GetSmoothing(DependencyObject obj) =>
+ (double)obj.GetValue(SmoothingProperty);
+
+ public static void SetSmoothing(DependencyObject obj, double value) =>
+ obj.SetValue(SmoothingProperty, value);
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
@@ -88,6 +131,8 @@ public static class SmoothScrollBehavior
return;
state.IsAttached = true;
+ state.PreviousCanContentScroll = sv.CanContentScroll;
+ sv.CanContentScroll = false;
sv.PreviewMouseWheel += OnPreviewMouseWheel;
sv.Unloaded += OnScrollViewerUnloaded;
}
@@ -99,6 +144,7 @@ public static class SmoothScrollBehavior
state.IsAttached = false;
state.IsAnimating = false;
+ sv.CanContentScroll = state.PreviousCanContentScroll;
sv.PreviewMouseWheel -= OnPreviewMouseWheel;
sv.Unloaded -= OnScrollViewerUnloaded;
RemoveActive(sv);
@@ -118,6 +164,9 @@ public static class SmoothScrollBehavior
{
try
{
+ if (!GlobalEnabled)
+ return;
+
if (sender is not ScrollViewer sv || !_stateTable.TryGetValue(sv, out var state))
return;
@@ -130,7 +179,10 @@ public static class SmoothScrollBehavior
e.Handled = true;
var delta = e.Delta / 120.0;
- var scrollDelta = GetScrollDelta(sv);
+
+ state.CachedScrollDelta = GetScrollDelta(sv);
+ state.CachedMultiplier = GetMultiplier(sv);
+ state.CachedSmoothing = GetSmoothing(sv);
if (!state.IsAnimating)
{
@@ -146,24 +198,38 @@ public static class SmoothScrollBehavior
}
}
- var multiplier = GetMultiplier(sv);
var now = DateTime.UtcNow.Ticks;
- var timeSinceLastScroll = TimeSpan.FromTicks(now - state.LastScrollTicks).TotalMilliseconds;
+ var timeSinceLastScroll = TimeSpan
+ .FromTicks(now - state.LastScrollTicks)
+ .TotalMilliseconds;
state.LastScrollTicks = now;
- var effectiveDelta = multiplier > 1.0 && timeSinceLastScroll < 400
- ? delta * scrollDelta * multiplier
- : delta * scrollDelta;
+ if (timeSinceLastScroll < 400)
+ state.RapidScrollCount++;
+ else
+ state.RapidScrollCount = 0;
+
+ var effectiveDelta = delta * state.CachedScrollDelta;
+ if (state.CachedMultiplier > 1.0 && state.RapidScrollCount >= 3)
+ effectiveDelta *= state.CachedMultiplier;
if (Keyboard.Modifiers == ModifierKeys.Shift)
{
if (sv.ScrollableWidth > 0)
- state.TargetX = Math.Clamp(state.TargetX - effectiveDelta, 0, sv.ScrollableWidth);
+ state.TargetX = Math.Clamp(
+ state.TargetX - effectiveDelta,
+ 0,
+ sv.ScrollableWidth
+ );
}
else
{
if (sv.ScrollableHeight > 0)
- state.TargetY = Math.Clamp(state.TargetY - effectiveDelta, 0, sv.ScrollableHeight);
+ state.TargetY = Math.Clamp(
+ state.TargetY - effectiveDelta,
+ 0,
+ sv.ScrollableHeight
+ );
}
}
catch (Exception ex)
@@ -200,12 +266,17 @@ public static class SmoothScrollBehavior
continue;
}
+ var smoothing = state.CachedSmoothing;
var active = false;
- var dy = state.TargetY - sv.VerticalOffset;
+ var currentY = sv.VerticalOffset;
+ var dy = state.TargetY - currentY;
if (Math.Abs(dy) > SnapThreshold)
{
- sv.ScrollToVerticalOffset(sv.VerticalOffset + dy * GetSmoothing(sv));
+ var stepY = dy * smoothing;
+ if (Math.Abs(stepY) > MaxScrollSpeedPerFrame)
+ stepY = Math.Sign(stepY) * MaxScrollSpeedPerFrame;
+ sv.ScrollToVerticalOffset(currentY + stepY);
active = true;
}
else if (dy != 0)
@@ -213,10 +284,14 @@ public static class SmoothScrollBehavior
sv.ScrollToVerticalOffset(state.TargetY);
}
- var dx = state.TargetX - sv.HorizontalOffset;
+ var currentX = sv.HorizontalOffset;
+ var dx = state.TargetX - currentX;
if (Math.Abs(dx) > SnapThreshold)
{
- sv.ScrollToHorizontalOffset(sv.HorizontalOffset + dx * GetSmoothing(sv));
+ var stepX = dx * smoothing;
+ if (Math.Abs(stepX) > MaxScrollSpeedPerFrame)
+ stepX = Math.Sign(stepX) * MaxScrollSpeedPerFrame;
+ sv.ScrollToHorizontalOffset(currentX + stepX);
active = true;
}
else if (dx != 0)
@@ -264,7 +339,11 @@ public static class SmoothScrollBehavior
{
while (element is not null && element != parent)
{
- if (element is ScrollViewer sv && sv != parent && (sv.ScrollableHeight > 0 || sv.ScrollableWidth > 0))
+ if (
+ element is ScrollViewer sv
+ && sv != parent
+ && (sv.ScrollableHeight > 0 || sv.ScrollableWidth > 0)
+ )
return true;
element = VisualTreeHelper.GetParent(element);
}
diff --git a/optimizerDuck/UI/Dialogs/OptimizationDetailsDialog.xaml b/optimizerDuck/UI/Dialogs/OptimizationDetailsDialog.xaml
index d89f655..79f2780 100644
--- a/optimizerDuck/UI/Dialogs/OptimizationDetailsDialog.xaml
+++ b/optimizerDuck/UI/Dialogs/OptimizationDetailsDialog.xaml
@@ -9,7 +9,6 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
d:DesignHeight="760"
d:DesignWidth="760"
- ScrollViewer.CanContentScroll="False"
mc:Ignorable="d">
<UserControl.Resources>
<converters:ValueConditionToVisibilityConverter
diff --git a/optimizerDuck/UI/Pages/BloatwarePage.xaml b/optimizerDuck/UI/Pages/BloatwarePage.xaml
index ceddc32..46feea4 100644
--- a/optimizerDuck/UI/Pages/BloatwarePage.xaml
+++ b/optimizerDuck/UI/Pages/BloatwarePage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
@@ -258,26 +257,24 @@
Text="{ext:Loc Bloatware.Search.NoResults}" />
</StackPanel>
- <ui:VirtualizingItemsControl
+ <ItemsControl
Grid.Row="2"
ItemsSource="{Binding ViewModel.AppxPackages}"
- VirtualizingPanel.IsVirtualizing="True"
- VirtualizingPanel.VirtualizationMode="Recycling"
Visibility="{Binding ViewModel.AppxPackages.Count, Converter={StaticResource GreaterThanZeroToVisibilityConverter}}">
- <ui:VirtualizingItemsControl.Template>
+ <ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
- <ItemsPresenter Margin="0,0,12,0" />
+ <ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
- </ui:VirtualizingItemsControl.Template>
- <ui:VirtualizingItemsControl.ItemsPanel>
+ </ItemsControl.Template>
+ <ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
- </ui:VirtualizingItemsControl.ItemsPanel>
+ </ItemsControl.ItemsPanel>
- <ui:VirtualizingItemsControl.ItemTemplate>
+ <ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type bloatware1:AppXPackage}">
<Border Style="{StaticResource ListRowStyle}">
<Grid>
@@ -387,8 +384,8 @@
</Grid>
</Border>
</DataTemplate>
- </ui:VirtualizingItemsControl.ItemTemplate>
- </ui:VirtualizingItemsControl>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
</Grid>
</Border>
</Grid>
diff --git a/optimizerDuck/UI/Pages/DashboardPage.xaml b/optimizerDuck/UI/Pages/DashboardPage.xaml
index c467224..797b3fe 100644
--- a/optimizerDuck/UI/Pages/DashboardPage.xaml
+++ b/optimizerDuck/UI/Pages/DashboardPage.xaml
@@ -14,7 +14,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
diff --git a/optimizerDuck/UI/Pages/DiskCleanupPage.xaml b/optimizerDuck/UI/Pages/DiskCleanupPage.xaml
index e4686a0..a6f4fa7 100644
--- a/optimizerDuck/UI/Pages/DiskCleanupPage.xaml
+++ b/optimizerDuck/UI/Pages/DiskCleanupPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
@@ -176,7 +175,7 @@
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
- <VirtualizingStackPanel />
+ <VirtualizingStackPanel VirtualizingStackPanel.VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
diff --git a/optimizerDuck/UI/Pages/Features/Categories/FeatureCategoryPage.xaml b/optimizerDuck/UI/Pages/Features/Categories/FeatureCategoryPage.xaml
index ec5f8b4..e5a632b 100644
--- a/optimizerDuck/UI/Pages/Features/Categories/FeatureCategoryPage.xaml
+++ b/optimizerDuck/UI/Pages/Features/Categories/FeatureCategoryPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
diff --git a/optimizerDuck/UI/Pages/Features/FeaturesPage.xaml b/optimizerDuck/UI/Pages/Features/FeaturesPage.xaml
index 9ee5173..176d10d 100644
--- a/optimizerDuck/UI/Pages/Features/FeaturesPage.xaml
+++ b/optimizerDuck/UI/Pages/Features/FeaturesPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
diff --git a/optimizerDuck/UI/Pages/Optimize/Categories/OptimizationPage.xaml b/optimizerDuck/UI/Pages/Optimize/Categories/OptimizationPage.xaml
index e702855..8a1f10c 100644
--- a/optimizerDuck/UI/Pages/Optimize/Categories/OptimizationPage.xaml
+++ b/optimizerDuck/UI/Pages/Optimize/Categories/OptimizationPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
@@ -196,10 +195,13 @@
<ui:VirtualizingItemsControl
Grid.Row="1"
ItemsSource="{Binding ViewModel.Optimizations}"
+ VirtualizingPanel.CacheLength="1"
+ VirtualizingPanel.CacheLengthUnit="Page"
+ VirtualizingStackPanel.VirtualizationMode="Recycling"
Visibility="{Binding ViewModel.Optimizations.Count, Converter={StaticResource GreaterThanZeroToVisibilityConverter}}">
<ui:VirtualizingItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
- <ScrollViewer HorizontalScrollBarVisibility="Disabled">
+ <ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Disabled">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
diff --git a/optimizerDuck/UI/Pages/Optimize/OptimizePage.xaml b/optimizerDuck/UI/Pages/Optimize/OptimizePage.xaml
index 17db081..a18c7af 100644
--- a/optimizerDuck/UI/Pages/Optimize/OptimizePage.xaml
+++ b/optimizerDuck/UI/Pages/Optimize/OptimizePage.xaml
@@ -12,7 +12,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Grid>
diff --git a/optimizerDuck/UI/Pages/ScheduledTasksPage.xaml b/optimizerDuck/UI/Pages/ScheduledTasksPage.xaml
index 370d655..eb86751 100644
--- a/optimizerDuck/UI/Pages/ScheduledTasksPage.xaml
+++ b/optimizerDuck/UI/Pages/ScheduledTasksPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
diff --git a/optimizerDuck/UI/Pages/SettingsPage.xaml b/optimizerDuck/UI/Pages/SettingsPage.xaml
index 531726a..7569867 100644
--- a/optimizerDuck/UI/Pages/SettingsPage.xaml
+++ b/optimizerDuck/UI/Pages/SettingsPage.xaml
@@ -2,6 +2,7 @@
x:Class="optimizerDuck.UI.Pages.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:behaviors="clr-namespace:optimizerDuck.UI.Behaviors"
xmlns:converters="clr-namespace:optimizerDuck.Common.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="clr-namespace:optimizerDuck.Common.Extensions"
@@ -68,6 +69,28 @@
</ComboBox>
</ui:CardControl>
+ <ui:CardControl Margin="0,0,0,4" Icon="{ui:SymbolIcon PhoneVerticalScroll24}">
+ <ui:CardControl.Header>
+ <StackPanel>
+ <ui:TextBlock
+ Margin="0"
+ FontTypography="BodyStrong"
+ Text="{ext:Loc Settings.Appearance.SmoothScrolling.Title}"
+ TextWrapping="Wrap" />
+ <ui:TextBlock
+ Foreground="{DynamicResource TextFillColorSecondaryBrush}"
+ Text="{ext:Loc Settings.Appearance.SmoothScrolling.Description}"
+ TextWrapping="Wrap" />
+ </StackPanel>
+ </ui:CardControl.Header>
+ <ui:ToggleSwitch
+ Command="{Binding ViewModel.ToggleSmoothScrollingCommand}"
+ Cursor="Hand"
+ IsChecked="{Binding ViewModel.SmoothScrolling, Mode=OneWay}"
+ OffContent="{ext:Loc Common.Toggle.Off}"
+ OnContent="{ext:Loc Common.Toggle.On}" />
+ </ui:CardControl>
+
<StackPanel Style="{StaticResource SettingsSectionStyle}">
<ui:TextBlock Style="{StaticResource SectionHeaderStyle}" Text="{ext:Loc Settings.Optimize.Header}" />
diff --git a/optimizerDuck/UI/Pages/StartupManagerPage.xaml b/optimizerDuck/UI/Pages/StartupManagerPage.xaml
index 77eaf42..6cb1aad 100644
--- a/optimizerDuck/UI/Pages/StartupManagerPage.xaml
+++ b/optimizerDuck/UI/Pages/StartupManagerPage.xaml
@@ -15,7 +15,6 @@
d:DesignWidth="800"
ui:Design.Background="Black"
ui:Design.Foreground="White"
- ScrollViewer.CanContentScroll="False"
Style="{StaticResource PageRootStyle}"
mc:Ignorable="d">
<Page.Resources>
diff --git a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
index 170dc5a..a7624b0 100644
--- a/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Optimizer/OptimizationCategoryViewModel.cs
@@ -164,7 +164,6 @@ public partial class OptimizationCategoryViewModel : ViewModel
var (proceed, created) = await HandleRestorePointAsync();
if (!proceed)
{
-
optimization.State.IsApplied = wasApplied;
return;
}
diff --git a/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs
index 4c7b785..06a8df1 100644
--- a/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Pages/ScheduledTasksViewModel.cs
@@ -167,8 +167,15 @@ public partial class ScheduledTasksViewModel : ViewModel
}
else
{
- var error = ScheduledTaskService.LastError ?? Translations.ScheduledTasks_Error_TaskNotFound;
- _logger.LogError("Failed to run task {Name} ({Path}): {Error}", task.Name, task.FullPath, error);
+ var error =
+ ScheduledTaskService.LastError
+ ?? Translations.ScheduledTasks_Error_TaskNotFound;
+ _logger.LogError(
+ "Failed to run task {Name} ({Path}): {Error}",
+ task.Name,
+ task.FullPath,
+ error
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
@@ -181,7 +188,12 @@ public partial class ScheduledTasksViewModel : ViewModel
}
catch (Exception ex)
{
- _logger.LogError(ex, "Unexpected error running task {Name} ({Path})", task.Name, task.FullPath);
+ _logger.LogError(
+ ex,
+ "Unexpected error running task {Name} ({Path})",
+ task.Name,
+ task.FullPath
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
@@ -218,8 +230,15 @@ public partial class ScheduledTasksViewModel : ViewModel
}
else
{
- var error = ScheduledTaskService.LastError ?? Translations.ScheduledTasks_Error_TaskNotFound;
- _logger.LogError("Failed to stop task {Name} ({Path}): {Error}", task.Name, task.FullPath, error);
+ var error =
+ ScheduledTaskService.LastError
+ ?? Translations.ScheduledTasks_Error_TaskNotFound;
+ _logger.LogError(
+ "Failed to stop task {Name} ({Path}): {Error}",
+ task.Name,
+ task.FullPath,
+ error
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
@@ -232,7 +251,12 @@ public partial class ScheduledTasksViewModel : ViewModel
}
catch (Exception ex)
{
- _logger.LogError(ex, "Unexpected error stopping task {Name} ({Path})", task.Name, task.FullPath);
+ _logger.LogError(
+ ex,
+ "Unexpected error stopping task {Name} ({Path})",
+ task.Name,
+ task.FullPath
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
@@ -282,8 +306,15 @@ public partial class ScheduledTasksViewModel : ViewModel
}
else
{
- var error = ScheduledTaskService.LastError ?? Translations.ScheduledTasks_Error_TaskNotFound;
- _logger.LogError("Failed to delete task {Name} ({Path}): {Error}", task.Name, task.FullPath, error);
+ var error =
+ ScheduledTaskService.LastError
+ ?? Translations.ScheduledTasks_Error_TaskNotFound;
+ _logger.LogError(
+ "Failed to delete task {Name} ({Path}): {Error}",
+ task.Name,
+ task.FullPath,
+ error
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
@@ -296,7 +327,12 @@ public partial class ScheduledTasksViewModel : ViewModel
}
catch (Exception ex)
{
- _logger.LogError(ex, "Unexpected error deleting task {Name} ({Path})", task.Name, task.FullPath);
+ _logger.LogError(
+ ex,
+ "Unexpected error deleting task {Name} ({Path})",
+ task.Name,
+ task.FullPath
+ );
_snackbarService.Show(
Translations.ScheduledTasks_Snackbar_Error_Title,
diff --git a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
index ddbc39b..3bc5dc3 100644
--- a/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
+++ b/optimizerDuck/UI/ViewModels/Pages/SettingsViewModel.cs
@@ -12,6 +12,7 @@ using optimizerDuck.Domain.UI;
using optimizerDuck.Resources.Languages;
using optimizerDuck.Services;
using optimizerDuck.Services.Managers;
+using optimizerDuck.UI.Behaviors;
using Wpf.Ui;
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
@@ -43,6 +44,9 @@ public partial class SettingsViewModel(
[ObservableProperty]
private bool _showSnackbarNotificationAfterAppliedSuccessfully;
+
+ [ObservableProperty]
+ private bool _smoothScrolling;
public string Version { get; } = Shared.FileVersion;
public ObservableCollection<LanguageOption> Languages { get; } =
@@ -73,6 +77,8 @@ public partial class SettingsViewModel(
.CurrentValue
.Optimize
.ShowCompletionNotification;
+ SmoothScrolling = appOptionsMonitor.CurrentValue.Optimize.SmoothScrolling;
+ SmoothScrollBehavior.GlobalEnabled = SmoothScrolling;
RemoveProvisioned = appOptionsMonitor.CurrentValue.Bloatware.RemoveProvisioned;
CurrentApplicationTheme = ApplicationThemeManager.GetAppTheme();
@@ -298,6 +304,27 @@ public partial class SettingsViewModel(
}
}
+ [RelayCommand]
+ private async Task ToggleSmoothScrolling()
+ {
+ if (!_isInitialized)
+ return;
+ try
+ {
+ await configManager.SetAsync(
+ "optimize:smoothScrolling",
+ (!appOptionsMonitor.CurrentValue.Optimize.SmoothScrolling).ToString()
+ );
+ SmoothScrolling = appOptionsMonitor.CurrentValue.Optimize.SmoothScrolling;
+ SmoothScrollBehavior.GlobalEnabled = SmoothScrolling;
+ }
+ catch (Exception ex)
+ {
+ logger.LogError(ex, "Failed to toggle SmoothScrolling setting");
+ SmoothScrolling = appOptionsMonitor.CurrentValue.Optimize.SmoothScrolling;
+ }
+ }
+
[RelayCommand]
private void OpenLatestRelease()
{
diff --git a/optimizerDuck/UI/Windows/MainWindow.xaml b/optimizerDuck/UI/Windows/MainWindow.xaml
index 8ca8cea..548f32f 100644
--- a/optimizerDuck/UI/Windows/MainWindow.xaml
+++ b/optimizerDuck/UI/Windows/MainWindow.xaml
@@ -13,6 +13,8 @@
Title="optimizerDuck"
Width="1350"
Height="800"
+ MinWidth="900"
+ MinHeight="500"
d:DataContext="{d:DesignInstance viewmodels:MainWindowViewModel}"
ui:Design.Background="Black"
ui:Design.Foreground="White"