From e50ac12c9ed5540354f613ac9f0aef4e10f5dcf2 Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 17 Jul 2023 23:26:23 -0700 Subject: [PATCH] Added NotificationService.Show overload & some install page fixes --- .../DesignData/MockNotificationService.cs | 4 ++++ .../Services/INotificationService.cs | 3 +++ .../Services/NotificationService.cs | 8 +++++++- .../ViewModels/Dialogs/InstallerViewModel.cs | 7 +++++-- .../ViewModels/LaunchPageViewModel.cs | 1 + .../ViewModels/PackageManagerViewModel.cs | 18 +++++++++++++++--- .../Views/Dialogs/InstallerDialog.axaml | 2 ++ .../Views/PackageManagerPage.axaml | 3 +-- .../Helper/Cache/GithubApiCache.cs | 3 +-- .../Models/Packages/VladAutomatic.cs | 2 +- 10 files changed, 40 insertions(+), 11 deletions(-) diff --git a/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs b/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs index 27257b98..790488ba 100644 --- a/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs +++ b/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs @@ -28,4 +28,8 @@ public class MockNotificationService : INotificationService { return Task.FromResult(new TaskResult(true)); } + + public void Show(string title, string message, NotificationType appearance = NotificationType.Information) + { + } } diff --git a/StabilityMatrix.Avalonia/Services/INotificationService.cs b/StabilityMatrix.Avalonia/Services/INotificationService.cs index 57664bd4..c8a0039c 100644 --- a/StabilityMatrix.Avalonia/Services/INotificationService.cs +++ b/StabilityMatrix.Avalonia/Services/INotificationService.cs @@ -40,4 +40,7 @@ public interface INotificationService string title = "Error", string? message = null, NotificationType appearance = NotificationType.Error); + + void Show(string title, string message, + NotificationType appearance = NotificationType.Information); } diff --git a/StabilityMatrix.Avalonia/Services/NotificationService.cs b/StabilityMatrix.Avalonia/Services/NotificationService.cs index b72dbcb4..153506da 100644 --- a/StabilityMatrix.Avalonia/Services/NotificationService.cs +++ b/StabilityMatrix.Avalonia/Services/NotificationService.cs @@ -28,7 +28,13 @@ public class NotificationService : INotificationService { notificationManager?.Show(notification); } - + + public void Show(string title, string message, + NotificationType appearance = NotificationType.Information) + { + Show(new Notification(title, message, appearance)); + } + /// public async Task> TryAsync( Task task, diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs index 8c48e321..f1522cdb 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs @@ -160,7 +160,9 @@ public partial class InstallerViewModel : ContentDialogViewModelBase if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled) { InstallProgress.Text = "Installing dependencies..."; + InstallProgress.IsIndeterminate = true; await pyRunner.Initialize(); + if (!PyRunner.PipInstalled) { await pyRunner.SetupPip(); @@ -190,7 +192,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase var package = new InstalledPackage { - DisplayName = SelectedPackage.DisplayName, + DisplayName = InstallName, LibraryPath = Path.Combine("Packages", InstallName), Id = Guid.NewGuid(), PackageName = SelectedPackage.Name, @@ -205,6 +207,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase st.Settings.ActiveInstalledPackage = package.Id; InstallProgress.Value = 0; + InstallProgress.IsIndeterminate = false; } private static string GetDisplayVersion(string version, string? branch) @@ -398,6 +401,6 @@ public partial class InstallerViewModel : ContentDialogViewModelBase }).SafeFireAndForget(); } } - + private void OnPackageInstalled() => PackageInstalled?.Invoke(this, EventArgs.Empty); } diff --git a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs index 81ba49c3..9b1f592c 100644 --- a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs @@ -91,6 +91,7 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable private async Task OnPackageLaunchRequested(object? sender, Guid e) { + OnLoaded(); SelectedPackage = InstalledPackages.FirstOrDefault(x => x.Id == e); if (SelectedPackage is null) return; diff --git a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs index c77afccf..fa4ac213 100644 --- a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs @@ -4,8 +4,10 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading.Tasks; +using AsyncAwaitBestPractices; using Avalonia.Controls; using Avalonia.Controls.Notifications; +using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; @@ -68,7 +70,7 @@ public partial class PackageManagerViewModel : PageViewModelBase [ObservableProperty] private string progressText = string.Empty; - [ObservableProperty] + [ObservableProperty, NotifyPropertyChangedFor(nameof(ProgressBarVisibility))] private bool isIndeterminate; [ObservableProperty] @@ -324,11 +326,17 @@ public partial class PackageManagerViewModel : PageViewModelBase errorMsg, NotificationType.Error)); } - ProgressText = "Update complete"; + ProgressText = string.Empty; + ProgressValue = 0; + IsIndeterminate = false; + SelectedPackage.UpdateAvailable = false; UpdateAvailable = false; settingsManager.UpdatePackageVersionNumber(SelectedPackage.Id, updateResult); + notificationService.Show("Update complete", + $"{SelectedPackage.DisplayName} has been updated to the latest version.", + NotificationType.Success); await OnLoadedAsync(); } @@ -352,7 +360,11 @@ public partial class PackageManagerViewModel : PageViewModelBase } }; - viewModel.PackageInstalled += (_, _) => dialog.Hide(); + viewModel.PackageInstalled += async (_, _) => + { + dialog.Hide(); + await OnLoadedAsync(); + }; await dialog.ShowAsync(); } diff --git a/StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml b/StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml index 36db6b68..d33136e7 100644 --- a/StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml +++ b/StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml @@ -44,6 +44,7 @@ @@ -197,6 +198,7 @@ diff --git a/StabilityMatrix.Core/Helper/Cache/GithubApiCache.cs b/StabilityMatrix.Core/Helper/Cache/GithubApiCache.cs index bb0c3d55..10c498bc 100644 --- a/StabilityMatrix.Core/Helper/Cache/GithubApiCache.cs +++ b/StabilityMatrix.Core/Helper/Cache/GithubApiCache.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Caching.Memory; -using Octokit; +using Octokit; using StabilityMatrix.Core.Database; using StabilityMatrix.Core.Models.Database; diff --git a/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs b/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs index f39c07ae..2d161bc9 100644 --- a/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs +++ b/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs @@ -260,7 +260,7 @@ public class VladAutomatic : BaseGitPackage return string.Empty; } - progress?.Report(new ProgressReport(1f, message: "Update Complete", isIndeterminate: true, type: ProgressType.Generic)); + progress?.Report(new ProgressReport(1f, message: "Update Complete", isIndeterminate: false, type: ProgressType.Generic)); return latest.Sha; }