Browse Source

Merge pull request #248 from ionite34/catch-install-errors

Catch & display install errors
pull/137/head
JT 1 year ago committed by GitHub
parent
commit
eaea3304d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  2. 7
      StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs
  3. 1
      StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs
  4. 20
      StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs

4
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -143,6 +143,9 @@ public partial class PackageManagerViewModel : PageViewModelBase
EventManager.Instance.OnPackageInstallProgressAdded(runner); EventManager.Instance.OnPackageInstallProgressAdded(runner);
await runner.ExecuteSteps(steps.ToList()); await runner.ExecuteSteps(steps.ToList());
if (!runner.Failed)
{
EventManager.Instance.OnInstalledPackagesChanged(); EventManager.Instance.OnInstalledPackagesChanged();
notificationService.Show( notificationService.Show(
"Package Install Complete", "Package Install Complete",
@ -151,6 +154,7 @@ public partial class PackageManagerViewModel : PageViewModelBase
); );
} }
} }
}
private IEnumerable<UnknownInstalledPackage> IndexUnknownPackages() private IEnumerable<UnknownInstalledPackage> IndexUnknownPackages()
{ {

7
StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs

@ -42,6 +42,7 @@ public class PackageInstallProgressItemViewModel : ProgressItemViewModelBase
Progress.IsIndeterminate = e.IsIndeterminate; Progress.IsIndeterminate = e.IsIndeterminate;
Progress.Text = packageModificationRunner.CurrentStep?.ProgressTitle; Progress.Text = packageModificationRunner.CurrentStep?.ProgressTitle;
Name = packageModificationRunner.CurrentStep?.ProgressTitle; Name = packageModificationRunner.CurrentStep?.ProgressTitle;
Failed = packageModificationRunner.Failed;
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Contains("Downloading...")) if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Contains("Downloading..."))
return; return;
@ -59,6 +60,12 @@ public class PackageInstallProgressItemViewModel : ProgressItemViewModelBase
{ {
Dispatcher.UIThread.Post(() => dialog?.Hide()); Dispatcher.UIThread.Post(() => dialog?.Hide());
} }
if (Failed)
{
Progress.Text = "Package Modification Failed";
Name = "Package Modification Failed";
}
} }
public async Task ShowProgressDialog() public async Task ShowProgressDialog()

1
StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs

@ -13,4 +13,5 @@ public interface IPackageModificationRunner
Guid Id { get; } Guid Id { get; }
bool ShowDialogOnStart { get; init; } bool ShowDialogOnStart { get; init; }
string? ModificationCompleteMessage { get; init; } string? ModificationCompleteMessage { get; init; }
bool Failed { get; set; }
} }

20
StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs

@ -21,9 +21,27 @@ public class PackageModificationRunner : IPackageModificationRunner
foreach (var step in steps) foreach (var step in steps)
{ {
CurrentStep = step; CurrentStep = step;
try
{
await step.ExecuteAsync(progress).ConfigureAwait(false); await step.ExecuteAsync(progress).ConfigureAwait(false);
} }
catch (Exception e)
{
progress.Report(
new ProgressReport(
1f,
title: "Error modifying package",
message: $"Error: {e}",
isIndeterminate: false
)
);
Failed = true;
break;
}
}
if (!Failed)
{
progress.Report( progress.Report(
new ProgressReport( new ProgressReport(
1f, 1f,
@ -31,6 +49,7 @@ public class PackageModificationRunner : IPackageModificationRunner
isIndeterminate: false isIndeterminate: false
) )
); );
}
IsRunning = false; IsRunning = false;
} }
@ -39,6 +58,7 @@ public class PackageModificationRunner : IPackageModificationRunner
public bool ShowDialogOnStart { get; init; } public bool ShowDialogOnStart { get; init; }
public bool IsRunning { get; set; } public bool IsRunning { get; set; }
public bool Failed { get; set; }
public ProgressReport CurrentProgress { get; set; } public ProgressReport CurrentProgress { get; set; }
public IPackageStep? CurrentStep { get; set; } public IPackageStep? CurrentStep { get; set; }
public List<string> ConsoleOutput { get; } = new(); public List<string> ConsoleOutput { get; } = new();

Loading…
Cancel
Save