From ada70d7957442a8cd334437cb141d1a40b278c7d Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Fri, 25 Aug 2023 19:09:36 -0400 Subject: [PATCH] udpate prechecks to use status spinner --- SPTInstaller/Controllers/InstallController.cs | 3 +- .../CustomControls/DetailedPreCheckItem.axaml | 54 ++--------------- .../CustomControls/PreCheckItem.axaml | 60 ++++--------------- .../CustomControls/PreCheckItem.axaml.cs | 38 ++++-------- .../Installer Tasks/PreChecks/TestPreCheck.cs | 30 ++++++++++ SPTInstaller/Interfaces/IPreCheck.cs | 9 +-- SPTInstaller/Models/PreCheckBase.cs | 39 +++++------- SPTInstaller/Program.cs | 16 +++-- .../Views/DetailedPreChecksView.axaml | 4 +- SPTInstaller/Views/PreChecksView.axaml | 4 +- 10 files changed, 92 insertions(+), 165 deletions(-) create mode 100644 SPTInstaller/Installer Tasks/PreChecks/TestPreCheck.cs diff --git a/SPTInstaller/Controllers/InstallController.cs b/SPTInstaller/Controllers/InstallController.cs index ac43ee6..e2b4b15 100644 --- a/SPTInstaller/Controllers/InstallController.cs +++ b/SPTInstaller/Controllers/InstallController.cs @@ -1,5 +1,6 @@ using Serilog; using SharpCompress; +using SPTInstaller.CustomControls; using SPTInstaller.Interfaces; using SPTInstaller.Models; using System.Collections.Generic; @@ -26,7 +27,7 @@ public class InstallController Log.Information("-<>--<>- Running PreChecks -<>--<>-"); var requiredResults = new List(); - _preChecks.ForEach(x => x.IsPending = true); + _preChecks.ForEach(x => x.State = StatusSpinner.SpinnerState.Pending); foreach (var check in _preChecks) { diff --git a/SPTInstaller/CustomControls/DetailedPreCheckItem.axaml b/SPTInstaller/CustomControls/DetailedPreCheckItem.axaml index de346ee..87c5d05 100644 --- a/SPTInstaller/CustomControls/DetailedPreCheckItem.axaml +++ b/SPTInstaller/CustomControls/DetailedPreCheckItem.axaml @@ -2,29 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:cc="using:SPTInstaller.CustomControls" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SPTInstaller.CustomControls.DetailedPreCheckItem" Background="Transparent" MinHeight="100"> - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/SPTInstaller/CustomControls/PreCheckItem.axaml b/SPTInstaller/CustomControls/PreCheckItem.axaml index 9d9a12b..68e7fb3 100644 --- a/SPTInstaller/CustomControls/PreCheckItem.axaml +++ b/SPTInstaller/CustomControls/PreCheckItem.axaml @@ -2,65 +2,29 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:cc="using:SPTInstaller.CustomControls" + xmlns:convt="using:SPTInstaller.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SPTInstaller.CustomControls.PreCheckItem"> - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/SPTInstaller/CustomControls/PreCheckItem.axaml.cs b/SPTInstaller/CustomControls/PreCheckItem.axaml.cs index 5b7182c..c531ccc 100644 --- a/SPTInstaller/CustomControls/PreCheckItem.axaml.cs +++ b/SPTInstaller/CustomControls/PreCheckItem.axaml.cs @@ -1,4 +1,4 @@ -using Avalonia; +using Avalonia; using Avalonia.Controls; namespace SPTInstaller.CustomControls; @@ -19,33 +19,6 @@ public partial class PreCheckItem : UserControl public static readonly StyledProperty PreCheckNameProperty = AvaloniaProperty.Register(nameof(PreCheckName)); - public bool IsRunning - { - get => GetValue(IsRunningProperty); - set => SetValue(IsRunningProperty, value); - } - - public static readonly StyledProperty IsRunningProperty = - AvaloniaProperty.Register(nameof(IsRunning)); - - public bool IsPending - { - get => GetValue(IsPendingProperty); - set => SetValue(IsPendingProperty, value); - } - - public static readonly StyledProperty IsPendingProperty = - AvaloniaProperty.Register(nameof(IsPending)); - - public bool Passed - { - get => GetValue(PassedProperty); - set => SetValue(PassedProperty, value); - } - - public static readonly StyledProperty PassedProperty = - AvaloniaProperty.Register(nameof(Passed)); - public bool IsRequired { get => GetValue(IsRequiredProperty); @@ -54,4 +27,13 @@ public partial class PreCheckItem : UserControl public static readonly StyledProperty IsRequiredProperty = AvaloniaProperty.Register(nameof(IsRequired)); + + public StatusSpinner.SpinnerState State + { + get => GetValue(StateProperty); + set => SetValue(StateProperty, value); + } + + public static readonly StyledProperty StateProperty = + AvaloniaProperty.Register(nameof(State)); } \ No newline at end of file diff --git a/SPTInstaller/Installer Tasks/PreChecks/TestPreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/TestPreCheck.cs new file mode 100644 index 0000000..3073cbb --- /dev/null +++ b/SPTInstaller/Installer Tasks/PreChecks/TestPreCheck.cs @@ -0,0 +1,30 @@ +using SPTInstaller.CustomControls; +using SPTInstaller.Models; +using System.Threading.Tasks; + +namespace SPTInstaller.Installer_Tasks.PreChecks; +public class TestPreCheck : PreCheckBase +{ + private StatusSpinner.SpinnerState _endState; + public static TestPreCheck FromRandomName(StatusSpinner.SpinnerState EndState) => new TestPreCheck($"{EndState} #{new Random().Next(0, 9999)}", EndState == StatusSpinner.SpinnerState.Error, EndState); + + public TestPreCheck(string name, bool isRequired, StatusSpinner.SpinnerState endState) : base(name, isRequired) + { + _endState = endState; + } + + public override async Task CheckOperation() + { + await Task.Delay(1000); + + switch (_endState) + { + case StatusSpinner.SpinnerState.Error: + return PreCheckResult.FromError("This is what a required precheck failing looks like"); + case StatusSpinner.SpinnerState.Warning: + return PreCheckResult.FromError("This is what a non-required precheck failing looks like"); + default: + return PreCheckResult.FromSuccess("This is what a successful precheck looks like"); + } + } +} diff --git a/SPTInstaller/Interfaces/IPreCheck.cs b/SPTInstaller/Interfaces/IPreCheck.cs index 1bc789c..53e9c0d 100644 --- a/SPTInstaller/Interfaces/IPreCheck.cs +++ b/SPTInstaller/Interfaces/IPreCheck.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using SPTInstaller.CustomControls; +using System.Threading.Tasks; namespace SPTInstaller.Interfaces; @@ -7,12 +8,8 @@ public interface IPreCheck public string Id { get; } public string Name { get; } public bool IsRequired { get; } - - public bool IsPending { get; set; } - - public bool Passed { get; } - public string PreCheckDetails { get; } + public StatusSpinner.SpinnerState State { get; set; } public Task RunCheck(); } \ No newline at end of file diff --git a/SPTInstaller/Models/PreCheckBase.cs b/SPTInstaller/Models/PreCheckBase.cs index 31bd45f..0e1fe0c 100644 --- a/SPTInstaller/Models/PreCheckBase.cs +++ b/SPTInstaller/Models/PreCheckBase.cs @@ -1,4 +1,5 @@ using ReactiveUI; +using SPTInstaller.CustomControls; using SPTInstaller.Interfaces; using System.Threading.Tasks; using System.Windows.Input; @@ -28,25 +29,11 @@ public abstract class PreCheckBase : ReactiveObject, IPreCheck set => this.RaiseAndSetIfChanged(ref _required, value); } - private bool _passed; - public bool Passed + private StatusSpinner.SpinnerState _state; + public StatusSpinner.SpinnerState State { - get => _passed; - set => this.RaiseAndSetIfChanged(ref _passed, value); - } - - private bool _isPending; - public bool IsPending - { - get => _isPending; - set => this.RaiseAndSetIfChanged(ref _isPending, value); - } - - private bool _isRunning; - public bool IsRunning - { - get => _isRunning; - set => this.RaiseAndSetIfChanged(ref _isRunning, value); + get => _state; + set => this.RaiseAndSetIfChanged(ref _state, value); } private string _preCheckDetails; @@ -89,12 +76,19 @@ public abstract class PreCheckBase : ReactiveObject, IPreCheck Id = Guid.NewGuid().ToString(); } + private StatusSpinner.SpinnerState ProcessResult(PreCheckResult result) => + (result.Succeeded, IsRequired) switch + { + (true, _) => StatusSpinner.SpinnerState.OK, + (false, false) => StatusSpinner.SpinnerState.Warning, + (_, _) => StatusSpinner.SpinnerState.Error + }; + public async Task RunCheck() { - IsRunning = true; + State = StatusSpinner.SpinnerState.Running; var result = await CheckOperation(); - Passed = result.Succeeded; PreCheckDetails = !string.IsNullOrWhiteSpace(result.Message) ? result.Message @@ -104,10 +98,9 @@ public abstract class PreCheckBase : ReactiveObject, IPreCheck ActionButtonCommand = result.ButtonPressedCommand; ActionButtonIsVisible = result.ActionButtonIsVisible; - IsRunning = false; - IsPending = false; + State = ProcessResult(result); - return Passed ? Result.FromSuccess() : Result.FromError($"PreCheck Failed: {Name}"); + return State == StatusSpinner.SpinnerState.OK ? Result.FromSuccess() : Result.FromError($"PreCheck Failed: {Name}"); } public abstract Task CheckOperation(); diff --git a/SPTInstaller/Program.cs b/SPTInstaller/Program.cs index d2635e7..43f5f78 100644 --- a/SPTInstaller/Program.cs +++ b/SPTInstaller/Program.cs @@ -4,6 +4,7 @@ using ReactiveUI; using Serilog; using Splat; using SPTInstaller.Controllers; +using SPTInstaller.CustomControls; using SPTInstaller.Helpers; using SPTInstaller.Installer_Tasks; using SPTInstaller.Installer_Tasks.PreChecks; @@ -31,10 +32,11 @@ internal class Program // Register all the things // Regestering as base classes so ReactiveUI works correctly. Doesn't seem to like the interfaces :( ServiceHelper.Register(); + +#if !TEST ServiceHelper.Register(); ServiceHelper.Register(); -#if !TEST ServiceHelper.Register(); var logPath = Path.Join(Environment.CurrentDirectory, "spt-aki-installer_.log"); @@ -52,10 +54,14 @@ internal class Program ServiceHelper.Register(); ServiceHelper.Register(); #else - for (int i = 0; i < 5; i++) - { - Locator.CurrentMutable.RegisterConstant(TestTask.FromRandomName()); - } + for (int i = 0; i < 5; i++) + { + Locator.CurrentMutable.RegisterConstant(TestTask.FromRandomName()); + } + + Locator.CurrentMutable.RegisterConstant(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.OK)); + Locator.CurrentMutable.RegisterConstant(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.Warning)); + Locator.CurrentMutable.RegisterConstant(TestPreCheck.FromRandomName(StatusSpinner.SpinnerState.Error)); #endif // need the interfaces for the controller and splat won't resolve them since we need to base classes in avalonia (what a mess), so doing it manually here diff --git a/SPTInstaller/Views/DetailedPreChecksView.axaml b/SPTInstaller/Views/DetailedPreChecksView.axaml index db78307..deec923 100644 --- a/SPTInstaller/Views/DetailedPreChecksView.axaml +++ b/SPTInstaller/Views/DetailedPreChecksView.axaml @@ -39,14 +39,12 @@ diff --git a/SPTInstaller/Views/PreChecksView.axaml b/SPTInstaller/Views/PreChecksView.axaml index 7e1ce53..540b250 100644 --- a/SPTInstaller/Views/PreChecksView.axaml +++ b/SPTInstaller/Views/PreChecksView.axaml @@ -36,10 +36,8 @@