diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageImportViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageImportViewModel.cs index 40ed6a88..428f5635 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/PackageImportViewModel.cs +++ b/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)); } } diff --git a/StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs index d8b538e9..04f33294 100644 --- a/StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs +++ b/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(vm => + var viewModel = vmFactory.Get(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 + { + 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()