JT
1 year ago
26 changed files with 377 additions and 79 deletions
@ -0,0 +1,11 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Base; |
||||
|
||||
public partial class ConsoleProgressViewModel : ProgressViewModel |
||||
{ |
||||
public ConsoleViewModel Console { get; } = new(); |
||||
|
||||
[ObservableProperty] |
||||
private bool closeWhenFinished; |
||||
} |
@ -0,0 +1,75 @@
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using FluentAvalonia.UI.Controls; |
||||
using StabilityMatrix.Avalonia.Controls; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Avalonia.Views.Dialogs; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.PackageModification; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels.Progress; |
||||
|
||||
public partial class PackageInstallProgressItemViewModel : ProgressItemViewModelBase |
||||
{ |
||||
private readonly IPackageModificationRunner packageModificationRunner; |
||||
private BetterContentDialog? dialog; |
||||
|
||||
public PackageInstallProgressItemViewModel(IPackageModificationRunner packageModificationRunner) |
||||
{ |
||||
this.packageModificationRunner = packageModificationRunner; |
||||
Id = packageModificationRunner.Id; |
||||
Name = packageModificationRunner.CurrentStep?.ProgressTitle; |
||||
Progress.Value = packageModificationRunner.CurrentProgress.Percentage; |
||||
Progress.Text = packageModificationRunner.ConsoleOutput.LastOrDefault(); |
||||
Progress.IsIndeterminate = packageModificationRunner.CurrentProgress.IsIndeterminate; |
||||
|
||||
Progress.Console.Post( |
||||
string.Join(Environment.NewLine, packageModificationRunner.ConsoleOutput) |
||||
); |
||||
|
||||
packageModificationRunner.ProgressChanged += PackageModificationRunnerOnProgressChanged; |
||||
} |
||||
|
||||
private void PackageModificationRunnerOnProgressChanged(object? sender, ProgressReport e) |
||||
{ |
||||
Progress.Value = e.Percentage; |
||||
Progress.Text = e.Message; |
||||
Progress.IsIndeterminate = e.IsIndeterminate; |
||||
Name = packageModificationRunner.CurrentStep?.ProgressTitle; |
||||
|
||||
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Equals("Downloading...")) |
||||
return; |
||||
|
||||
Progress.Console.PostLine(e.Message); |
||||
EventManager.Instance.OnScrollToBottomRequested(); |
||||
|
||||
if ( |
||||
e is { Message: not null, Percentage: >= 100 } |
||||
&& e.Message.Contains("Package Install Complete") |
||||
&& Progress.CloseWhenFinished |
||||
) |
||||
{ |
||||
EventManager.Instance.OnInstalledPackagesChanged(); |
||||
dialog?.Hide(); |
||||
} |
||||
} |
||||
|
||||
public async Task ShowProgressDialog() |
||||
{ |
||||
Progress.CloseWhenFinished = true; |
||||
dialog = new BetterContentDialog |
||||
{ |
||||
MaxDialogWidth = 900, |
||||
MinDialogWidth = 900, |
||||
DefaultButton = ContentDialogButton.Close, |
||||
IsPrimaryButtonEnabled = false, |
||||
IsSecondaryButtonEnabled = false, |
||||
IsFooterVisible = false, |
||||
Content = new PackageModificationDialog { DataContext = Progress } |
||||
}; |
||||
EventManager.Instance.OnToggleProgressFlyout(); |
||||
await dialog.ShowAsync(); |
||||
} |
||||
} |
@ -1,10 +1,8 @@
|
||||
using System; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Avalonia.ViewModels.Base; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
|
||||
namespace StabilityMatrix.Avalonia.ViewModels; |
||||
namespace StabilityMatrix.Avalonia.ViewModels.Progress; |
||||
|
||||
public class ProgressItemViewModel : ProgressItemViewModelBase |
||||
{ |
@ -0,0 +1,24 @@
|
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Core.Models.PackageModification; |
||||
|
||||
public class SetPackageInstallingStep : IPackageStep |
||||
{ |
||||
private readonly ISettingsManager settingsManager; |
||||
private readonly string packageName; |
||||
|
||||
public SetPackageInstallingStep(ISettingsManager settingsManager, string packageName) |
||||
{ |
||||
this.settingsManager = settingsManager; |
||||
this.packageName = packageName; |
||||
} |
||||
|
||||
public Task ExecuteAsync(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
settingsManager.PackageInstallsInProgress.Add(packageName); |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
public string ProgressTitle => "Starting Package Installation"; |
||||
} |
@ -1,3 +1,8 @@
|
||||
namespace StabilityMatrix.Core.Models.Progress; |
||||
|
||||
public record ProgressItem(Guid ProgressId, string Name, ProgressReport Progress, bool Failed = false); |
||||
public record ProgressItem( |
||||
Guid ProgressId, |
||||
string Name, |
||||
ProgressReport Progress, |
||||
bool Failed = false |
||||
); |
||||
|
Loading…
Reference in new issue