From 4bb623c64e451bcca993a9d933027538d5ede9ac Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Fri, 25 Oct 2024 20:43:00 +0100 Subject: [PATCH] Add debounce for installer navigation buttons --- Bloxstrap/UI/Elements/Installer/MainWindow.xaml.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Bloxstrap/UI/Elements/Installer/MainWindow.xaml.cs b/Bloxstrap/UI/Elements/Installer/MainWindow.xaml.cs index 6e1926b..8198509 100644 --- a/Bloxstrap/UI/Elements/Installer/MainWindow.xaml.cs +++ b/Bloxstrap/UI/Elements/Installer/MainWindow.xaml.cs @@ -31,9 +31,7 @@ namespace Bloxstrap.UI.Elements.Installer /// - MainWindow has a single-set Func property named NextPageCallback which is reset on every page load /// - This callback is called when the next page button is pressed /// - Page CodeBehind gets MainWindow and sets the callback to its own local function on page load - /// - CodeBehind's local function then directly calls the ViewModel to do whatever it needs to do - /// - /// TODO: theme selection + /// - CodeBehind's local function then directly calls its ViewModel to do whatever it needs to do public partial class MainWindow : WpfUiWindow, INavigationWindow { @@ -43,6 +41,8 @@ namespace Bloxstrap.UI.Elements.Installer private List _pages = new() { typeof(WelcomePage), typeof(InstallPage), typeof(CompletionPage) }; + private DateTimeOffset _lastNavigation = DateTimeOffset.Now; + public Func? NextPageCallback; public NextAction CloseAction = NextAction.Terminate; @@ -55,10 +55,16 @@ namespace Bloxstrap.UI.Elements.Installer _viewModel.PageRequest += (_, type) => { + // debounce + if (DateTimeOffset.Now.Subtract(_lastNavigation).TotalMilliseconds < 500) + return; + if (type == "next") NextPage(); else if (type == "back") BackPage(); + + _lastNavigation = DateTimeOffset.Now; }; DataContext = _viewModel;