implement re-evaluation requests on prechecks

This commit is contained in:
IsWaffle 2023-11-09 10:32:36 -05:00
parent f837e02ec0
commit ad37a15a92
4 changed files with 45 additions and 0 deletions

View File

@ -11,8 +11,10 @@ namespace SPTInstaller.Controllers;
public class InstallController
{
public event EventHandler RecheckRequested = delegate { };
public event EventHandler<IProgressableTask> TaskChanged = delegate { };
private bool _installRunning = false;
private IPreCheck[] _preChecks { get; set; }
private IProgressableTask[] _tasks { get; set; }
@ -20,6 +22,22 @@ public class InstallController
{
_tasks = tasks;
_preChecks = preChecks;
_preChecks.ForEach(x => x.ReeevaluationRequested += (s, e) =>
{
if (s is IPreCheck preCheck)
{
Log.Information($"{preCheck.Name}: requested re-evaluation");
if (_installRunning)
{
Log.Warning("Install is running, re-evaluation denied (how did you do this?)");
return;
}
RecheckRequested?.Invoke(this, null);
}
});
}
public async Task<IResult> RunPreChecks()
@ -51,6 +69,8 @@ public class InstallController
public async Task<IResult> RunTasks()
{
_installRunning = true;
Log.Information("-<>--<>- Running Installer Tasks -<>--<>-");
foreach (var task in _tasks)

View File

@ -10,6 +10,7 @@ public interface IPreCheck
public bool IsRequired { get; }
public string PreCheckDetails { get; }
public StatusSpinner.SpinnerState State { get; set; }
public event EventHandler ReeevaluationRequested;
public Task<IResult> RunCheck();
}

View File

@ -8,6 +8,7 @@ namespace SPTInstaller.Models;
public abstract class PreCheckBase : ReactiveObject, IPreCheck
{
public event EventHandler ReeevaluationRequested = delegate { };
private string _id;
public string Id
{
@ -84,6 +85,14 @@ public abstract class PreCheckBase : ReactiveObject, IPreCheck
(_, _) => StatusSpinner.SpinnerState.Error
};
/// <summary>
/// Request pre-checks to be re-evaluated
/// </summary>
public void RequestReevaluation()
{
ReeevaluationRequested?.Invoke(this, null);
}
public async Task<IResult> RunCheck()
{
State = StatusSpinner.SpinnerState.Running;

View File

@ -79,11 +79,25 @@ public class PreChecksViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _installButtonCheckState, value);
}
private void ReCheckRequested(object? sender, EventArgs e)
{
Task.Run(async () =>
{
if (sender is InstallController installer)
{
var result = await installer.RunPreChecks();
AllowInstall = result.Succeeded;
}
});
}
public PreChecksViewModel(IScreen host) : base(host)
{
var data = ServiceHelper.Get<InternalData?>();
var installer = ServiceHelper.Get<InstallController?>();
installer.RecheckRequested += ReCheckRequested;
InstallButtonText = "Please wait ...";
InstallButtonCheckState = StatusSpinner.SpinnerState.Pending;
@ -158,6 +172,7 @@ public class PreChecksViewModel : ViewModelBase
{
UpdateInfo.ShowCard = false;
Log.Logger.Information("Opening Detailed PreCheck View");
installer.RecheckRequested -= ReCheckRequested;
NavigateTo(new DetailedPreChecksViewModel(HostScreen));
});