|
|
|
@ -1,18 +1,12 @@
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Immutable; |
|
|
|
|
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; |
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
using Polly; |
|
|
|
|
using StabilityMatrix.Avalonia.Controls; |
|
|
|
|
using StabilityMatrix.Avalonia.Services; |
|
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Dialogs; |
|
|
|
@ -22,9 +16,6 @@ using StabilityMatrix.Avalonia.Views.Dialogs;
|
|
|
|
|
using StabilityMatrix.Core.Attributes; |
|
|
|
|
using StabilityMatrix.Core.Helper; |
|
|
|
|
using StabilityMatrix.Core.Helper.Factory; |
|
|
|
|
using StabilityMatrix.Core.Models; |
|
|
|
|
using StabilityMatrix.Core.Models.Packages; |
|
|
|
|
using StabilityMatrix.Core.Models.Progress; |
|
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
|
using Symbol = FluentIcons.Common.Symbol; |
|
|
|
|
using SymbolIconSource = FluentIcons.FluentAvalonia.SymbolIconSource; |
|
|
|
@ -38,28 +29,16 @@ namespace StabilityMatrix.Avalonia.ViewModels;
|
|
|
|
|
[View(typeof(PackageManagerPage))] |
|
|
|
|
public partial class PackageManagerViewModel : PageViewModelBase |
|
|
|
|
{ |
|
|
|
|
private readonly ILogger<PackageManagerViewModel> logger; |
|
|
|
|
private readonly ISettingsManager settingsManager; |
|
|
|
|
private readonly IPackageFactory packageFactory; |
|
|
|
|
private readonly INotificationService notificationService; |
|
|
|
|
private readonly ServiceManager<ViewModelBase> dialogFactory; |
|
|
|
|
|
|
|
|
|
private const int MinutesToWaitForUpdateCheck = 60; |
|
|
|
|
|
|
|
|
|
public PackageManagerViewModel(ILogger<PackageManagerViewModel> logger, |
|
|
|
|
ISettingsManager settingsManager, IPackageFactory packageFactory, |
|
|
|
|
INotificationService notificationService, ServiceManager<ViewModelBase> dialogFactory) |
|
|
|
|
public PackageManagerViewModel(ISettingsManager settingsManager, IPackageFactory packageFactory, |
|
|
|
|
ServiceManager<ViewModelBase> dialogFactory) |
|
|
|
|
{ |
|
|
|
|
this.logger = logger; |
|
|
|
|
this.settingsManager = settingsManager; |
|
|
|
|
this.packageFactory = packageFactory; |
|
|
|
|
this.notificationService = notificationService; |
|
|
|
|
this.dialogFactory = dialogFactory; |
|
|
|
|
|
|
|
|
|
Packages = |
|
|
|
|
new ObservableCollection<PackageCardViewModel>( |
|
|
|
|
settingsManager.Settings.InstalledPackages.Select(p => |
|
|
|
|
dialogFactory.Get<PackageCardViewModel>(vm => vm.Package = p))); |
|
|
|
|
|
|
|
|
|
EventManager.Instance.InstalledPackagesChanged += OnInstalledPackagesChanged; |
|
|
|
|
} |
|
|
|
@ -70,15 +49,25 @@ public partial class PackageManagerViewModel : PageViewModelBase
|
|
|
|
|
public override bool CanNavigatePrevious { get; protected set; } |
|
|
|
|
public override string Title => "Packages"; |
|
|
|
|
public override IconSource IconSource => new SymbolIconSource { Symbol = Symbol.Box, IsFilled = true}; |
|
|
|
|
|
|
|
|
|
public override void OnLoaded() |
|
|
|
|
|
|
|
|
|
public override async Task OnLoadedAsync() |
|
|
|
|
{ |
|
|
|
|
Packages = |
|
|
|
|
new ObservableCollection<PackageCardViewModel>( |
|
|
|
|
settingsManager.Settings.InstalledPackages.Select(p => |
|
|
|
|
dialogFactory.Get<PackageCardViewModel>(vm => vm.Package = p))); |
|
|
|
|
if (Design.IsDesignMode) return; |
|
|
|
|
|
|
|
|
|
var installedPackages = settingsManager.Settings.InstalledPackages; |
|
|
|
|
Packages = new ObservableCollection<PackageCardViewModel>(installedPackages.Select( |
|
|
|
|
package => dialogFactory.Get<PackageCardViewModel>(vm => |
|
|
|
|
{ |
|
|
|
|
vm.Package = package; |
|
|
|
|
return vm; |
|
|
|
|
}))); |
|
|
|
|
|
|
|
|
|
foreach (var package in Packages) |
|
|
|
|
{ |
|
|
|
|
await package.OnLoadedAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task ShowInstallDialog() |
|
|
|
|
{ |
|
|
|
|
var viewModel = dialogFactory.Get<InstallerViewModel>(); |
|
|
|
@ -100,8 +89,8 @@ public partial class PackageManagerViewModel : PageViewModelBase
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
await dialog.ShowAsync(); |
|
|
|
|
OnLoaded(); |
|
|
|
|
await OnLoadedAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void OnInstalledPackagesChanged(object? sender, EventArgs e) => OnLoaded(); |
|
|
|
|
|
|
|
|
|
private void OnInstalledPackagesChanged(object? sender, EventArgs e) =>OnLoaded(); |
|
|
|
|
} |
|
|
|
|