Browse Source

Added NotificationService.Show overload & some install page fixes

pull/55/head
JT 1 year ago
parent
commit
e50ac12c9e
  1. 4
      StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs
  2. 3
      StabilityMatrix.Avalonia/Services/INotificationService.cs
  3. 8
      StabilityMatrix.Avalonia/Services/NotificationService.cs
  4. 7
      StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs
  5. 1
      StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs
  6. 18
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  7. 2
      StabilityMatrix.Avalonia/Views/Dialogs/InstallerDialog.axaml
  8. 3
      StabilityMatrix.Avalonia/Views/PackageManagerPage.axaml
  9. 3
      StabilityMatrix.Core/Helper/Cache/GithubApiCache.cs
  10. 2
      StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

4
StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs

@ -28,4 +28,8 @@ public class MockNotificationService : INotificationService
{ {
return Task.FromResult(new TaskResult<bool>(true)); return Task.FromResult(new TaskResult<bool>(true));
} }
public void Show(string title, string message, NotificationType appearance = NotificationType.Information)
{
}
} }

3
StabilityMatrix.Avalonia/Services/INotificationService.cs

@ -40,4 +40,7 @@ public interface INotificationService
string title = "Error", string title = "Error",
string? message = null, string? message = null,
NotificationType appearance = NotificationType.Error); NotificationType appearance = NotificationType.Error);
void Show(string title, string message,
NotificationType appearance = NotificationType.Information);
} }

8
StabilityMatrix.Avalonia/Services/NotificationService.cs

@ -28,7 +28,13 @@ public class NotificationService : INotificationService
{ {
notificationManager?.Show(notification); notificationManager?.Show(notification);
} }
public void Show(string title, string message,
NotificationType appearance = NotificationType.Information)
{
Show(new Notification(title, message, appearance));
}
/// <inheritdoc /> /// <inheritdoc />
public async Task<TaskResult<T>> TryAsync<T>( public async Task<TaskResult<T>> TryAsync<T>(
Task<T> task, Task<T> task,

7
StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs

@ -160,7 +160,9 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled) if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled)
{ {
InstallProgress.Text = "Installing dependencies..."; InstallProgress.Text = "Installing dependencies...";
InstallProgress.IsIndeterminate = true;
await pyRunner.Initialize(); await pyRunner.Initialize();
if (!PyRunner.PipInstalled) if (!PyRunner.PipInstalled)
{ {
await pyRunner.SetupPip(); await pyRunner.SetupPip();
@ -190,7 +192,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
var package = new InstalledPackage var package = new InstalledPackage
{ {
DisplayName = SelectedPackage.DisplayName, DisplayName = InstallName,
LibraryPath = Path.Combine("Packages", InstallName), LibraryPath = Path.Combine("Packages", InstallName),
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
PackageName = SelectedPackage.Name, PackageName = SelectedPackage.Name,
@ -205,6 +207,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
st.Settings.ActiveInstalledPackage = package.Id; st.Settings.ActiveInstalledPackage = package.Id;
InstallProgress.Value = 0; InstallProgress.Value = 0;
InstallProgress.IsIndeterminate = false;
} }
private static string GetDisplayVersion(string version, string? branch) private static string GetDisplayVersion(string version, string? branch)
@ -398,6 +401,6 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
}).SafeFireAndForget(); }).SafeFireAndForget();
} }
} }
private void OnPackageInstalled() => PackageInstalled?.Invoke(this, EventArgs.Empty); private void OnPackageInstalled() => PackageInstalled?.Invoke(this, EventArgs.Empty);
} }

1
StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs

@ -91,6 +91,7 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable
private async Task OnPackageLaunchRequested(object? sender, Guid e) private async Task OnPackageLaunchRequested(object? sender, Guid e)
{ {
OnLoaded();
SelectedPackage = InstalledPackages.FirstOrDefault(x => x.Id == e); SelectedPackage = InstalledPackages.FirstOrDefault(x => x.Id == e);
if (SelectedPackage is null) return; if (SelectedPackage is null) return;

18
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -4,8 +4,10 @@ using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Notifications; using Avalonia.Controls.Notifications;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
@ -68,7 +70,7 @@ public partial class PackageManagerViewModel : PageViewModelBase
[ObservableProperty] [ObservableProperty]
private string progressText = string.Empty; private string progressText = string.Empty;
[ObservableProperty] [ObservableProperty, NotifyPropertyChangedFor(nameof(ProgressBarVisibility))]
private bool isIndeterminate; private bool isIndeterminate;
[ObservableProperty] [ObservableProperty]
@ -324,11 +326,17 @@ public partial class PackageManagerViewModel : PageViewModelBase
errorMsg, NotificationType.Error)); errorMsg, NotificationType.Error));
} }
ProgressText = "Update complete"; ProgressText = string.Empty;
ProgressValue = 0;
IsIndeterminate = false;
SelectedPackage.UpdateAvailable = false; SelectedPackage.UpdateAvailable = false;
UpdateAvailable = false; UpdateAvailable = false;
settingsManager.UpdatePackageVersionNumber(SelectedPackage.Id, updateResult); settingsManager.UpdatePackageVersionNumber(SelectedPackage.Id, updateResult);
notificationService.Show("Update complete",
$"{SelectedPackage.DisplayName} has been updated to the latest version.",
NotificationType.Success);
await OnLoadedAsync(); 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(); await dialog.ShowAsync();
} }

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

@ -44,6 +44,7 @@
<Grid Grid.Row="2" HorizontalAlignment="Left" ColumnDefinitions="Auto,*,Auto"> <Grid Grid.Row="2" HorizontalAlignment="Left" ColumnDefinitions="Auto,*,Auto">
<ListBox <ListBox
Margin="8,16" Margin="8,16"
IsEnabled="{Binding !InstallProgress.IsProgressVisible}"
ItemsSource="{Binding AvailablePackages}" ItemsSource="{Binding AvailablePackages}"
SelectedItem="{Binding SelectedPackage, Mode=TwoWay}"> SelectedItem="{Binding SelectedPackage, Mode=TwoWay}">
@ -197,6 +198,7 @@
<controls:ProgressRing <controls:ProgressRing
Height="25" Height="25"
IsIndeterminate="True" IsIndeterminate="True"
BorderThickness="4"
Margin="8,16,0,0" Margin="8,16,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding InstallProgress.IsProgressVisible}" IsVisible="{Binding InstallProgress.IsProgressVisible}"

3
StabilityMatrix.Avalonia/Views/PackageManagerPage.axaml

@ -108,8 +108,7 @@
Height="50" Height="50"
VerticalAlignment="Top" VerticalAlignment="Top"
Classes="danger" Classes="danger"
IsEnabled="{Binding SelectedPackage, Converter={x:Static ObjectConverters.IsNotNull}}" IsEnabled="{Binding !IsUninstalling}"
IsVisible="{Binding SelectedPackage, Converter={x:Static ObjectConverters.IsNotNull}}"
Width="100" /> Width="100" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" IsVisible="{Binding IsUninstalling}"> <StackPanel Orientation="Horizontal" IsVisible="{Binding IsUninstalling}">

3
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.Database;
using StabilityMatrix.Core.Models.Database; using StabilityMatrix.Core.Models.Database;

2
StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

@ -260,7 +260,7 @@ public class VladAutomatic : BaseGitPackage
return string.Empty; 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; return latest.Sha;
} }

Loading…
Cancel
Save