From 6cde6ef4702134129c0daab14343beb8829fdcde Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 23 Jul 2023 18:44:30 -0400 Subject: [PATCH] Add Debug mode toggle for version button --- .../ViewModels/SettingsViewModel.cs | 56 ++++++++++++++++--- .../Views/SettingsPage.axaml | 14 ++++- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs index 2c15b6e6..0437c1ee 100644 --- a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs @@ -10,6 +10,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; using NLog; +using StabilityMatrix.Avalonia.Models; using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.Views; using StabilityMatrix.Core.Attributes; @@ -31,6 +32,7 @@ public partial class SettingsViewModel : PageViewModelBase private readonly ISettingsManager settingsManager; private readonly IPrerequisiteHelper prerequisiteHelper; private readonly IPyRunner pyRunner; + public SharedState SharedState { get; } public override string Title => "Settings"; public override IconSource IconSource => new SymbolIconSource {Symbol = Symbol.Settings, IsFilled = true}; @@ -41,6 +43,13 @@ public partial class SettingsViewModel : PageViewModelBase // Theme section [ObservableProperty] private string? selectedTheme; + public IReadOnlyList AvailableThemes { get; } = new[] + { + "Light", + "Dark", + "System", + }; + // Shared folder options [ObservableProperty] private bool removeSymlinksOnShutdown; @@ -49,23 +58,24 @@ public partial class SettingsViewModel : PageViewModelBase [ObservableProperty] private string? debugCompatInfo; [ObservableProperty] private string? debugGpuInfo; - public IReadOnlyList AvailableThemes { get; } = new[] - { - "Light", - "Dark", - "System", - }; + // Info section + private const int VersionTapCountThreshold = 7; + [ObservableProperty, NotifyPropertyChangedFor(nameof(VersionFlyoutText))] private int versionTapCount; + [ObservableProperty] private bool isVersionTapTeachingTipOpen; + public string VersionFlyoutText => $"You are {VersionTapCountThreshold - VersionTapCount} clicks away from enabling Debug options."; public SettingsViewModel( INotificationService notificationService, ISettingsManager settingsManager, IPrerequisiteHelper prerequisiteHelper, - IPyRunner pyRunner) + IPyRunner pyRunner, + SharedState sharedState) { this.notificationService = notificationService; this.settingsManager = settingsManager; this.prerequisiteHelper = prerequisiteHelper; this.pyRunner = pyRunner; + SharedState = sharedState; SelectedTheme = AvailableThemes[1]; RemoveSymlinksOnShutdown = settingsManager.Settings.RemoveFolderLinksOnShutdown; @@ -197,6 +207,36 @@ public partial class SettingsViewModel : PageViewModelBase throw new OperationCanceledException("Example Message"); } #endregion - + + #region Info Section + + public void OnVersionClick() + { + // Ignore if already enabled + if (SharedState.IsDebugMode) return; + + VersionTapCount++; + + switch (VersionTapCount) + { + // Reached required threshold + case >= VersionTapCountThreshold: + { + IsVersionTapTeachingTipOpen = false; + // Enable debug options + SharedState.IsDebugMode = true; + notificationService.Show( + "Debug options enabled", "Warning: Improper use may corrupt application state or cause loss of data."); + VersionTapCount = 0; + break; + } + // Open teaching tip above 3rd click + case >= 3: + IsVersionTapTeachingTipOpen = true; + break; + } + } + + #endregion } diff --git a/StabilityMatrix.Avalonia/Views/SettingsPage.axaml b/StabilityMatrix.Avalonia/Views/SettingsPage.axaml index c702a170..7911d3c3 100644 --- a/StabilityMatrix.Avalonia/Views/SettingsPage.axaml +++ b/StabilityMatrix.Avalonia/Views/SettingsPage.axaml @@ -76,7 +76,8 @@ - + + - +