Browse Source

Add progress and venv/model migration for imports

pull/109/head
Ionite 1 year ago
parent
commit
52bd14144f
No known key found for this signature in database
  1. 11
      StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageImportViewModel.cs
  2. 58
      StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

11
StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageImportViewModel.cs

@ -183,7 +183,7 @@ public partial class PackageImportViewModel : ContentDialogViewModelBase
}
}
public void AddPackageWithCurrentInputs()
public async Task AddPackageWithCurrentInputs()
{
if (SelectedBasePackage is null || PackagePath is null)
return;
@ -216,6 +216,15 @@ public partial class PackageImportViewModel : ContentDialogViewModelBase
LastUpdateCheck = DateTimeOffset.Now,
};
// Recreate venv if it's a BaseGitPackage
if (SelectedBasePackage is BaseGitPackage gitPackage)
{
await gitPackage.SetupVenv(PackagePath, forceRecreate: true);
}
// Reconfigure shared links
await SelectedBasePackage.UpdateModelFolders(PackagePath);
settingsManager.Transaction(s => s.InstalledPackages.Add(package));
}
}

58
StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
@ -11,6 +12,7 @@ using StabilityMatrix.Avalonia.Languages;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
@ -219,23 +221,55 @@ public partial class PackageCardViewModel : ProgressViewModel
{
if (!IsUnknownPackage || Design.IsDesignMode) return;
PackageImportViewModel viewModel = null!;
var dialog = vmFactory.GetDialog<PackageImportViewModel>(vm =>
var viewModel = vmFactory.Get<PackageImportViewModel>(vm =>
{
vm.PackagePath = new DirectoryPath(Package?.FullPath ?? throw new InvalidOperationException());
viewModel = vm;
vm.PackagePath =
new DirectoryPath(Package?.FullPath ?? throw new InvalidOperationException());
});
dialog.PrimaryButtonText = Resources.Action_Import;
dialog.CloseButtonText = Resources.Action_Cancel;
dialog.DefaultButton = ContentDialogButton.Primary;
var dialog = new TaskDialog
{
Content = new PackageImportDialog
{
DataContext = viewModel
},
ShowProgressBar = false,
Buttons = new List<TaskDialogButton>
{
new(Resources.Action_Import, TaskDialogStandardResult.Yes)
{
IsDefault = true
},
new(Resources.Action_Cancel, TaskDialogStandardResult.Cancel)
}
};
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
dialog.Closing += async (sender, e) =>
{
viewModel.AddPackageWithCurrentInputs();
EventManager.Instance.OnInstalledPackagesChanged();
}
// We only want to use the deferral on the 'Yes' Button
if ((TaskDialogStandardResult)e.Result == TaskDialogStandardResult.Yes)
{
var deferral = e.GetDeferral();
sender.ShowProgressBar = true;
sender.SetProgressBarState(0, TaskDialogProgressState.Indeterminate);
await using (new MinimumDelay(200, 300))
{
var result = await notificationService.TryAsync(viewModel.AddPackageWithCurrentInputs());
if (result.IsSuccessful)
{
EventManager.Instance.OnInstalledPackagesChanged();
}
}
deferral.Complete();
}
};
dialog.XamlRoot = App.VisualRoot;
await dialog.ShowAsync(true);
}
public async Task OpenFolder()

Loading…
Cancel
Save