diff --git a/StabilityMatrix.Avalonia/Controls/BetterContentDialog.cs b/StabilityMatrix.Avalonia/Controls/BetterContentDialog.cs index 7a6b6d23..a0c27988 100644 --- a/StabilityMatrix.Avalonia/Controls/BetterContentDialog.cs +++ b/StabilityMatrix.Avalonia/Controls/BetterContentDialog.cs @@ -144,6 +144,17 @@ public class BetterContentDialog : ContentDialog set => SetValue(MaxDialogWidthProperty, value); } + public static readonly StyledProperty MinDialogHeightProperty = AvaloniaProperty.Register< + BetterContentDialog, + double + >("MinDialogHeight"); + + public double MinDialogHeight + { + get => GetValue(MaxDialogHeightProperty); + set => SetValue(MaxDialogHeightProperty, value); + } + public static readonly StyledProperty MaxDialogHeightProperty = AvaloniaProperty.Register< BetterContentDialog, double diff --git a/StabilityMatrix.Avalonia/DesignData/DesignData.cs b/StabilityMatrix.Avalonia/DesignData/DesignData.cs index 15784042..72b56c78 100644 --- a/StabilityMatrix.Avalonia/DesignData/DesignData.cs +++ b/StabilityMatrix.Avalonia/DesignData/DesignData.cs @@ -444,6 +444,9 @@ public static class DesignData public static HuggingFacePageViewModel HuggingFacePageViewModel => Services.GetRequiredService(); + public static NewOneClickInstallViewModel NewOneClickInstallViewModel => + Services.GetRequiredService(); + public static OutputsPageViewModel OutputsPageViewModel { get diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/NewOneClickInstallViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/NewOneClickInstallViewModel.cs new file mode 100644 index 00000000..f22cfeb2 --- /dev/null +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/NewOneClickInstallViewModel.cs @@ -0,0 +1,61 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using DynamicData; +using DynamicData.Binding; +using StabilityMatrix.Avalonia.ViewModels.Base; +using StabilityMatrix.Avalonia.Views.Dialogs; +using StabilityMatrix.Core.Attributes; +using StabilityMatrix.Core.Helper.Factory; +using StabilityMatrix.Core.Models.Packages; + +namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; + +[Transient] +[ManagedService] +public partial class NewOneClickInstallViewModel : ContentDialogViewModelBase +{ + public SourceCache AllPackagesCache { get; } = new(p => p.Author + p.Name); + + public IObservableCollection ShownPackages { get; set; } = + new ObservableCollectionExtended(); + + [ObservableProperty] + private bool showIncompatiblePackages; + + public NewOneClickInstallViewModel(IPackageFactory packageFactory) + { + var incompatiblePredicate = this.WhenPropertyChanged(vm => vm.ShowIncompatiblePackages) + .Select(_ => new Func(p => p.IsCompatible || ShowIncompatiblePackages)) + .AsObservable(); + + AllPackagesCache + .Connect() + .DeferUntilLoaded() + .Filter(incompatiblePredicate) + .Filter(p => p.OfferInOneClickInstaller || ShowIncompatiblePackages) + .Sort( + SortExpressionComparer + .Ascending(p => p.InstallerSortOrder) + .ThenByAscending(p => p.DisplayName) + ) + .Bind(ShownPackages) + .Subscribe(); + + AllPackagesCache.AddOrUpdate(packageFactory.GetAllAvailablePackages()); + } + + [RelayCommand] + private async Task InstallComfyForInference() + { + var comfyPackage = ShownPackages.FirstOrDefault(x => x is ComfyUI); + if (comfyPackage != null) + { + // install + } + } +} diff --git a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs index 76d486ad..beb352ae 100644 --- a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs @@ -128,13 +128,15 @@ public partial class MainWindowViewModel : ViewModelBase if (Program.Args.DebugOneClickInstall || settingsManager.Settings.InstalledPackages.Count == 0) { - var viewModel = dialogFactory.Get(); + var viewModel = dialogFactory.Get(); var dialog = new BetterContentDialog { IsPrimaryButtonEnabled = false, IsSecondaryButtonEnabled = false, IsFooterVisible = false, - Content = new OneClickInstallDialog { DataContext = viewModel }, + FullSizeDesired = true, + MinDialogHeight = 775, + Content = new NewOneClickInstallDialog { DataContext = viewModel }, }; EventManager.Instance.OneClickInstallFinished += (_, skipped) => diff --git a/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml b/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml new file mode 100644 index 00000000..324ff96c --- /dev/null +++ b/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml.cs b/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml.cs new file mode 100644 index 00000000..9930025a --- /dev/null +++ b/StabilityMatrix.Avalonia/Views/Dialogs/NewOneClickInstallDialog.axaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Linq; +using Avalonia.Controls; +using Avalonia.Interactivity; +using FluentAvalonia.UI.Controls; +using KGySoft.CoreLibraries; +using StabilityMatrix.Avalonia.Controls; +using StabilityMatrix.Core.Models.Packages; + +namespace StabilityMatrix.Avalonia.Views.Dialogs; + +public partial class NewOneClickInstallDialog : UserControlBase +{ + public NewOneClickInstallDialog() + { + InitializeComponent(); + } + + protected override void OnLoaded(RoutedEventArgs e) + { + base.OnLoaded(e); + + var teachingTip = + this.FindControl("InferenceTeachingTip") + ?? throw new InvalidOperationException("TeachingTip not found"); + + teachingTip.ActionButtonClick += (_, _) => + { + teachingTip.IsOpen = false; + }; + + // Find ComfyUI listbox item + var listBox = this.FindControl("PackagesRepeater"); + + // Find ComfyUI listbox item + if (listBox?.ItemsSource?.Cast().FirstOrDefault(p => p is ComfyUI) is { } comfy) + { + var comfyItem = listBox.TryGetElement(listBox?.ItemsSource?.IndexOf(comfy) ?? 0); + + // comfyItem!.IsSelected = true; + + teachingTip.Target = comfyItem; + teachingTip.IsOpen = true; + } + } +} diff --git a/StabilityMatrix.Avalonia/Views/PackageManager/PackageInstallBrowserView.axaml b/StabilityMatrix.Avalonia/Views/PackageManager/PackageInstallBrowserView.axaml index dc8ba2ca..b88f7717 100644 --- a/StabilityMatrix.Avalonia/Views/PackageManager/PackageInstallBrowserView.axaml +++ b/StabilityMatrix.Avalonia/Views/PackageManager/PackageInstallBrowserView.axaml @@ -20,7 +20,7 @@ - +