Browse Source

Remove PackageModificationDialogViewModel & call Console.StartUpdates

pull/117/head
JT 1 year ago
parent
commit
ff240ca1d0
  1. 3
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 75
      StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageModificationDialogViewModel.cs
  3. 33
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  4. 8
      StabilityMatrix.Avalonia/ViewModels/Progress/PackageInstallProgressItemViewModel.cs
  5. 39
      StabilityMatrix.Avalonia/ViewModels/Progress/ProgressManagerViewModel.cs
  6. 1
      StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml
  7. 1
      StabilityMatrix.Avalonia/Views/Dialogs/PackageModificationDialog.axaml

3
StabilityMatrix.Avalonia/App.axaml.cs

@ -605,6 +605,9 @@ public sealed class App : Application
builder.ForLogger("System.*").WriteToNil(NLog.LogLevel.Warn);
builder.ForLogger("Microsoft.*").WriteToNil(NLog.LogLevel.Warn);
builder.ForLogger("Microsoft.Extensions.Http.*").WriteToNil(NLog.LogLevel.Warn);
builder
.ForLogger("StabilityMatrix.Avalonia.ViewModels.ConsoleViewModel")
.WriteToNil(NLog.LogLevel.Debug);
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(debugTarget);
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteTo(fileTarget);

75
StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageModificationDialogViewModel.cs

@ -1,75 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls.Notifications;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.PackageModification;
using StabilityMatrix.Core.Models.Progress;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
public class PackageModificationDialogViewModel : ContentDialogProgressViewModelBase
{
private readonly IPackageModificationRunner packageModificationRunner;
private readonly INotificationService notificationService;
private readonly IEnumerable<IPackageStep> steps;
public PackageModificationDialogViewModel(
IPackageModificationRunner packageModificationRunner,
INotificationService notificationService,
IEnumerable<IPackageStep> steps
)
{
this.packageModificationRunner = packageModificationRunner;
this.notificationService = notificationService;
this.steps = steps;
CloseWhenFinished = true;
}
public override async Task OnLoadedAsync()
{
await Console.Clear();
Console.Post(string.Join(Environment.NewLine, packageModificationRunner.ConsoleOutput));
// idk why this is getting called twice
if (!packageModificationRunner.IsRunning)
{
EventManager.Instance.OnPackageInstallProgressAdded(packageModificationRunner);
packageModificationRunner.ProgressChanged += PackageModificationRunnerOnProgressChanged;
await packageModificationRunner.ExecuteSteps(steps.ToList());
notificationService.Show(
"Package Install Completed",
"Package install completed successfully.",
NotificationType.Success
);
EventManager.Instance.OnInstalledPackagesChanged();
if (CloseWhenFinished)
{
OnCloseButtonClick();
}
}
}
private void PackageModificationRunnerOnProgressChanged(object? sender, ProgressReport e)
{
Text = string.IsNullOrWhiteSpace(e.Title)
? packageModificationRunner.CurrentStep?.ProgressTitle
: e.Title;
Value = e.Percentage;
Description = e.Message;
IsIndeterminate = e.IsIndeterminate;
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Equals("Downloading..."))
return;
Console.PostLine(e.Message);
EventManager.Instance.OnScrollToBottomRequested();
}
}

33
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using DynamicData;
using DynamicData.Binding;
using FluentAvalonia.UI.Controls;
@ -38,7 +39,6 @@ public partial class PackageManagerViewModel : PageViewModelBase
private readonly ISettingsManager settingsManager;
private readonly IPackageFactory packageFactory;
private readonly ServiceManager<ViewModelBase> dialogFactory;
private readonly IPackageModificationRunner packageModificationRunner;
private readonly INotificationService notificationService;
public override string Title => "Packages";
@ -65,14 +65,12 @@ public partial class PackageManagerViewModel : PageViewModelBase
ISettingsManager settingsManager,
IPackageFactory packageFactory,
ServiceManager<ViewModelBase> dialogFactory,
IPackageModificationRunner packageModificationRunner,
INotificationService notificationService
)
{
this.settingsManager = settingsManager;
this.packageFactory = packageFactory;
this.dialogFactory = dialogFactory;
this.packageModificationRunner = packageModificationRunner;
this.notificationService = notificationService;
EventManager.Instance.InstalledPackagesChanged += OnInstalledPackagesChanged;
@ -140,28 +138,17 @@ public partial class PackageManagerViewModel : PageViewModelBase
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
var runner = new PackageModificationRunner();
var steps = viewModel.Steps;
var packageModificationDialogViewModel = new PackageModificationDialogViewModel(
packageModificationRunner,
notificationService,
steps
);
dialog = new BetterContentDialog
{
MaxDialogWidth = 900,
MinDialogWidth = 900,
DefaultButton = ContentDialogButton.Close,
IsPrimaryButtonEnabled = false,
IsSecondaryButtonEnabled = false,
IsFooterVisible = false,
Content = new PackageModificationDialog
{
DataContext = packageModificationDialogViewModel
}
};
await dialog.ShowAsync();
EventManager.Instance.OnPackageInstallProgressAdded(runner);
await runner.ExecuteSteps(steps.ToList());
EventManager.Instance.OnInstalledPackagesChanged();
notificationService.Show(
"Package Install Complete",
$"{viewModel.InstallName} installed successfully",
NotificationType.Success
);
}
}

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

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.ViewModels.Base;
@ -25,6 +26,8 @@ public partial class PackageInstallProgressItemViewModel : ProgressItemViewModel
Progress.Text = packageModificationRunner.ConsoleOutput.LastOrDefault();
Progress.IsIndeterminate = packageModificationRunner.CurrentProgress.IsIndeterminate;
Progress.Console.StartUpdates();
Progress.Console.Post(
string.Join(Environment.NewLine, packageModificationRunner.ConsoleOutput)
);
@ -39,7 +42,7 @@ public partial class PackageInstallProgressItemViewModel : ProgressItemViewModel
Progress.IsIndeterminate = e.IsIndeterminate;
Name = packageModificationRunner.CurrentStep?.ProgressTitle;
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Equals("Downloading..."))
if (string.IsNullOrWhiteSpace(e.Message) || e.Message.Contains("Downloading..."))
return;
Progress.Console.PostLine(e.Message);
@ -51,8 +54,7 @@ public partial class PackageInstallProgressItemViewModel : ProgressItemViewModel
&& Progress.CloseWhenFinished
)
{
EventManager.Instance.OnInstalledPackagesChanged();
dialog?.Hide();
Dispatcher.UIThread.Post(() => dialog?.Hide());
}
}

39
StabilityMatrix.Avalonia/ViewModels/Progress/ProgressManagerViewModel.cs

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Collections;
using Avalonia.Controls.Notifications;
using Avalonia.Threading;
@ -25,14 +27,17 @@ public partial class ProgressManagerViewModel : PageViewModelBase
private readonly INotificationService notificationService;
public override string Title => "Download Manager";
public override IconSource IconSource => new SymbolIconSource {Symbol = Symbol.ArrowCircleDown, IsFilled = true};
public override IconSource IconSource =>
new SymbolIconSource { Symbol = Symbol.ArrowCircleDown, IsFilled = true };
public AvaloniaList<ProgressItemViewModelBase> ProgressItems { get; } = new();
[ObservableProperty] private bool isOpen;
[ObservableProperty]
private bool isOpen;
public ProgressManagerViewModel(
ITrackedDownloadService trackedDownloadService,
INotificationService notificationService)
INotificationService notificationService
)
{
this.notificationService = notificationService;
@ -42,9 +47,12 @@ public partial class ProgressManagerViewModel : PageViewModelBase
EventManager.Instance.ToggleProgressFlyout += (_, _) => IsOpen = !IsOpen;
}
private void InstanceOnPackageInstallProgressAdded(object? sender, IPackageModificationRunner runner)
private void InstanceOnPackageInstallProgressAdded(
object? sender,
IPackageModificationRunner runner
)
{
AddPackageInstall(runner);
AddPackageInstall(runner).SafeFireAndForget();
}
private void TrackedDownloadService_OnDownloadAdded(object? sender, TrackedDownload e)
@ -61,7 +69,11 @@ public partial class ProgressManagerViewModel : PageViewModelBase
case ProgressState.Success:
Dispatcher.UIThread.Post(() =>
{
notificationService.Show("Download Completed", $"Download of {e.FileName} completed successfully.", NotificationType.Success);
notificationService.Show(
"Download Completed",
$"Download of {e.FileName} completed successfully.",
NotificationType.Success
);
});
break;
case ProgressState.Failed:
@ -72,13 +84,21 @@ public partial class ProgressManagerViewModel : PageViewModelBase
}
Dispatcher.UIThread.Post(() =>
{
notificationService.ShowPersistent("Download Failed", $"Download of {e.FileName} failed: {msg}", NotificationType.Error);
notificationService.ShowPersistent(
"Download Failed",
$"Download of {e.FileName} failed: {msg}",
NotificationType.Error
);
});
break;
case ProgressState.Cancelled:
Dispatcher.UIThread.Post(() =>
{
notificationService.Show("Download Cancelled", $"Download of {e.FileName} was cancelled.", NotificationType.Warning);
notificationService.Show(
"Download Cancelled",
$"Download of {e.FileName} was cancelled.",
NotificationType.Warning
);
});
break;
}
@ -100,7 +120,7 @@ public partial class ProgressManagerViewModel : PageViewModelBase
}
}
private void AddPackageInstall(IPackageModificationRunner packageModificationRunner)
private async Task AddPackageInstall(IPackageModificationRunner packageModificationRunner)
{
if (ProgressItems.Any(vm => vm.Id == packageModificationRunner.Id))
{
@ -109,6 +129,7 @@ public partial class ProgressManagerViewModel : PageViewModelBase
var vm = new PackageInstallProgressItemViewModel(packageModificationRunner);
ProgressItems.Add(vm);
await vm.ShowProgressDialog();
}
private void ShowFailedNotification(string title, string message)

1
StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml

@ -197,6 +197,7 @@
Content="Install"
Command="{Binding InstallCommand}"
FontSize="20"
IsEnabled="{Binding !ShowDuplicateWarning}"
HorizontalAlignment="Center"
Classes="success"
Margin="4,0,8,0"

1
StabilityMatrix.Avalonia/Views/Dialogs/PackageModificationDialog.axaml

@ -12,6 +12,7 @@
<Grid Margin="8" RowDefinitions="Auto, Auto, Auto, *, Auto, Auto">
<TextBlock Grid.Row="0" Text="{Binding Text}"
FontSize="16"
Margin="4"
TextAlignment="Center"
HorizontalAlignment="Center"/>

Loading…
Cancel
Save