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. 16
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  2. 7
      StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs
  3. 1
      StabilityMatrix.Core/Models/PackageModification/IPackageModificationRunner.cs
  4. 36
      StabilityMatrix.Core/Models/PackageModification/PackageModificationRunner.cs

16
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -143,12 +143,16 @@ public partial class PackageManagerViewModel : PageViewModelBase
EventManager.Instance.OnPackageInstallProgressAdded(runner); EventManager.Instance.OnPackageInstallProgressAdded(runner);
await runner.ExecuteSteps(steps.ToList()); await runner.ExecuteSteps(steps.ToList());
EventManager.Instance.OnInstalledPackagesChanged();
notificationService.Show( if (!runner.Failed)
"Package Install Complete", {
$"{viewModel.InstallName} installed successfully", EventManager.Instance.OnInstalledPackagesChanged();
NotificationType.Success notificationService.Show(
); "Package Install Complete",
$"{viewModel.InstallName} installed successfully",
NotificationType.Success
);
}
} }
} }

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; }
} }

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

@ -21,16 +21,35 @@ public class PackageModificationRunner : IPackageModificationRunner
foreach (var step in steps) foreach (var step in steps)
{ {
CurrentStep = step; CurrentStep = step;
await step.ExecuteAsync(progress).ConfigureAwait(false); try
{
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;
}
} }
progress.Report( if (!Failed)
new ProgressReport( {
1f, progress.Report(
message: ModificationCompleteMessage ?? "Package Install Complete", new ProgressReport(
isIndeterminate: false 1f,
) message: ModificationCompleteMessage ?? "Package Install Complete",
); 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