Add debounce for installer navigation buttons

This commit is contained in:
pizzaboxer 2024-10-25 20:43:00 +01:00
parent 4c29b1b6e6
commit 4bb623c64e
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8

View File

@ -31,9 +31,7 @@ namespace Bloxstrap.UI.Elements.Installer
/// - MainWindow has a single-set Func<bool> 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<Type> _pages = new() { typeof(WelcomePage), typeof(InstallPage), typeof(CompletionPage) };
private DateTimeOffset _lastNavigation = DateTimeOffset.Now;
public Func<bool>? 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;