Browse Source

Add Debug mode toggle for version button

pull/55/head
Ionite 1 year ago
parent
commit
6cde6ef470
No known key found for this signature in database
  1. 56
      StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs
  2. 14
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml

56
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<string> 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<string> 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
}

14
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -76,7 +76,8 @@
</StackPanel>
</Grid>
<Grid RowDefinitions="auto,*">
<!-- Debug Options -->
<Grid RowDefinitions="auto,*" IsVisible="{Binding SharedState.IsDebugMode}">
<TextBlock
FontWeight="Medium"
Text="Debug Options"
@ -161,14 +162,21 @@
FontWeight="Medium"
Margin="8"
Text="Stability Matrix" />
<Grid>
<Panel>
<Button
Name="VersionButton"
Command="{Binding OnVersionClick}"
Classes="transparent"
BorderThickness="0"
Content="{Binding AppVersion}"
Margin="8,0,8,8"
Padding="2,0,2,0"/>
</Grid>
<ui:TeachingTip
PreferredPlacement="RightTop"
Target="{Binding #VersionButton}"
IsOpen="{Binding IsVersionTapTeachingTipOpen}"
Title="{Binding VersionFlyoutText}"/>
</Panel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<Button

Loading…
Cancel
Save