Browse Source

Merge branch 'main' into fix-stuff

pull/55/head
Ionite 1 year ago committed by GitHub
parent
commit
b482842af4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      StabilityMatrix.Avalonia/DesignData/DesignData.cs
  2. 5
      StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserCardViewModel.cs
  3. 10
      StabilityMatrix.Avalonia/ViewModels/Dialogs/CivitFileViewModel.cs
  4. 8
      StabilityMatrix.Avalonia/ViewModels/Dialogs/ModelVersionViewModel.cs
  5. 70
      StabilityMatrix.Avalonia/Views/Dialogs/SelectModelVersionDialog.axaml
  6. 2
      StabilityMatrix.Avalonia/Views/MainWindow.axaml

64
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -96,22 +96,6 @@ public static class DesignData
var packageFactory = Services.GetRequiredService<IPackageFactory>(); var packageFactory = Services.GetRequiredService<IPackageFactory>();
var notificationService = Services.GetRequiredService<INotificationService>(); var notificationService = Services.GetRequiredService<INotificationService>();
// Sample data
var sampleCivitVersions = new List<CivitModelVersion>
{
new()
{
Name = "BB95 Furry Mix",
Description = "v1.0.0",
}
};
var sampleViewModel = new ModelVersionViewModel(settingsManager, sampleCivitVersions[0]);
// Sample data for dialogs
SelectModelVersionViewModel.Versions = new[] {sampleViewModel};
SelectModelVersionViewModel.SelectedVersionViewModel = sampleViewModel;
LaunchOptionsViewModel = Services.GetRequiredService<LaunchOptionsViewModel>(); LaunchOptionsViewModel = Services.GetRequiredService<LaunchOptionsViewModel>();
LaunchOptionsViewModel.Cards = new[] LaunchOptionsViewModel.Cards = new[]
{ {
@ -240,7 +224,53 @@ public static class DesignData
public static CheckpointBrowserViewModel CheckpointBrowserViewModel => public static CheckpointBrowserViewModel CheckpointBrowserViewModel =>
Services.GetRequiredService<CheckpointBrowserViewModel>(); Services.GetRequiredService<CheckpointBrowserViewModel>();
public static SelectModelVersionViewModel SelectModelVersionViewModel => public static SelectModelVersionViewModel SelectModelVersionViewModel =>
Services.GetRequiredService<SelectModelVersionViewModel>(); DialogFactory.Get<SelectModelVersionViewModel>(vm =>
{
// Sample data
var sampleCivitVersions = new List<CivitModelVersion>
{
new()
{
Name = "BB95 Furry Mix",
Description = "v1.0.0",
Files = new List<CivitFile>
{
new()
{
Name = "bb95-v100-uwu-reallylongfilename-v1234576802.safetensors",
Type = CivitFileType.Model,
Metadata = new CivitFileMetadata
{
Format = CivitModelFormat.SafeTensor,
Fp = CivitModelFpType.fp16,
Size = CivitModelSize.pruned
}
},
new()
{
Name = "bb95-v100-uwu-reallylongfilename-v1234576802-fp32.safetensors",
Type = CivitFileType.Model,
Metadata = new CivitFileMetadata
{
Format = CivitModelFormat.SafeTensor,
Fp = CivitModelFpType.fp32,
Size = CivitModelSize.full
},
Hashes = new CivitFileHashes
{
BLAKE3 = "ABCD"
}
}
}
}
};
var sampleViewModel =
new ModelVersionViewModel(new HashSet<string> {"ABCD"}, sampleCivitVersions[0]);
// Sample data for dialogs
vm.Versions = new List<ModelVersionViewModel>{sampleViewModel};
vm.SelectedVersionViewModel = sampleViewModel;
});
public static OneClickInstallViewModel OneClickInstallViewModel => public static OneClickInstallViewModel OneClickInstallViewModel =>
Services.GetRequiredService<OneClickInstallViewModel>(); Services.GetRequiredService<OneClickInstallViewModel>();
public static SelectDataDirectoryViewModel SelectDataDirectoryViewModel => public static SelectDataDirectoryViewModel SelectDataDirectoryViewModel =>

5
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserCardViewModel.cs

@ -156,11 +156,14 @@ public partial class CheckpointBrowserCardViewModel : ProgressViewModel
IsPrimaryButtonEnabled = false, IsPrimaryButtonEnabled = false,
IsSecondaryButtonEnabled = false, IsSecondaryButtonEnabled = false,
IsFooterVisible = false, IsFooterVisible = false,
MaxDialogWidth = 750,
}; };
var viewModel = dialogFactory.Get<SelectModelVersionViewModel>(); var viewModel = dialogFactory.Get<SelectModelVersionViewModel>();
viewModel.Dialog = dialog; viewModel.Dialog = dialog;
viewModel.Versions = versions.Select(v => new ModelVersionViewModel(settingsManager, v)) viewModel.Versions = versions.Select(version =>
new ModelVersionViewModel(
settingsManager.Settings.InstalledModelHashes ?? new HashSet<string>(), version))
.ToImmutableArray(); .ToImmutableArray();
viewModel.SelectedVersionViewModel = viewModel.Versions[0]; viewModel.SelectedVersionViewModel = viewModel.Versions[0];

10
StabilityMatrix.Avalonia/ViewModels/Dialogs/CivitFileViewModel.cs

@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel; using System.Collections.Generic;
using System.IO;
using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Core.Models.Api; using StabilityMatrix.Core.Models.Api;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs; namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
@ -9,11 +10,10 @@ public partial class CivitFileViewModel : ObservableObject
[ObservableProperty] private CivitFile civitFile; [ObservableProperty] private CivitFile civitFile;
[ObservableProperty] private bool isInstalled; [ObservableProperty] private bool isInstalled;
public CivitFileViewModel(ISettingsManager settingsManager, CivitFile civitFile) public CivitFileViewModel(HashSet<string> installedModelHashes, CivitFile civitFile)
{ {
CivitFile = civitFile; CivitFile = civitFile;
CivitFile.Name = Path.GetFileNameWithoutExtension(CivitFile.Name);
var installedModelHashes = settingsManager.Settings.InstalledModelHashes;
IsInstalled = CivitFile is {Type: CivitFileType.Model, Hashes.BLAKE3: not null} && IsInstalled = CivitFile is {Type: CivitFileType.Model, Hashes.BLAKE3: not null} &&
installedModelHashes.Contains(CivitFile.Hashes.BLAKE3); installedModelHashes.Contains(CivitFile.Hashes.BLAKE3);
} }

8
StabilityMatrix.Avalonia/ViewModels/Dialogs/ModelVersionViewModel.cs

@ -13,18 +13,16 @@ public partial class ModelVersionViewModel : ObservableObject
[ObservableProperty] private ObservableCollection<CivitFileViewModel> civitFileViewModels; [ObservableProperty] private ObservableCollection<CivitFileViewModel> civitFileViewModels;
[ObservableProperty] private bool isInstalled; [ObservableProperty] private bool isInstalled;
public ModelVersionViewModel(ISettingsManager settingsManager, CivitModelVersion modelVersion) public ModelVersionViewModel(HashSet<string> installedModelHashes, CivitModelVersion modelVersion)
{ {
ModelVersion = modelVersion; ModelVersion = modelVersion;
var installedModelHashes = settingsManager.Settings.InstalledModelHashes;
IsInstalled = ModelVersion.Files?.Any(file => IsInstalled = ModelVersion.Files?.Any(file =>
file is {Type: CivitFileType.Model, Hashes.BLAKE3: not null} && file is {Type: CivitFileType.Model, Hashes.BLAKE3: not null} &&
installedModelHashes.Contains(file.Hashes.BLAKE3)) ?? installedModelHashes.Contains(file.Hashes.BLAKE3)) ?? false;
false;
CivitFileViewModels = new ObservableCollection<CivitFileViewModel>( CivitFileViewModels = new ObservableCollection<CivitFileViewModel>(
ModelVersion.Files?.Select(file => new CivitFileViewModel(settingsManager, file)) ?? ModelVersion.Files?.Select(file => new CivitFileViewModel(installedModelHashes, file)) ??
new List<CivitFileViewModel>()); new List<CivitFileViewModel>());
} }
} }

70
StabilityMatrix.Avalonia/Views/Dialogs/SelectModelVersionDialog.axaml

@ -6,7 +6,7 @@
xmlns:api="clr-namespace:StabilityMatrix.Core.Models.Api;assembly=StabilityMatrix.Core" xmlns:api="clr-namespace:StabilityMatrix.Core.Models.Api;assembly=StabilityMatrix.Core"
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs" xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs"
xmlns:designData="clr-namespace:StabilityMatrix.Avalonia.DesignData" xmlns:designData="clr-namespace:StabilityMatrix.Avalonia.DesignData"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="700" d:DesignHeight="450"
x:DataType="dialogs:SelectModelVersionViewModel" x:DataType="dialogs:SelectModelVersionViewModel"
xmlns:icons="https://github.com/projektanker/icons.avalonia" xmlns:icons="https://github.com/projektanker/icons.avalonia"
xmlns:fluentAvalonia="clr-namespace:FluentIcons.FluentAvalonia;assembly=FluentIcons.FluentAvalonia" xmlns:fluentAvalonia="clr-namespace:FluentIcons.FluentAvalonia;assembly=FluentIcons.FluentAvalonia"
@ -26,53 +26,77 @@
Source="{Binding PreviewImage}" /> Source="{Binding PreviewImage}" />
<TreeView Grid.Row="0" Grid.Column="1" <ListBox Grid.Row="0" Grid.Column="1"
Margin="8" Margin="8"
MaxHeight="450" MaxHeight="450"
ItemsSource="{Binding Versions}" ItemsSource="{Binding Versions}"
SelectedItem="{Binding SelectedVersionViewModel}"> SelectedItem="{Binding SelectedVersionViewModel}">
<TreeView.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type dialogs:ModelVersionViewModel}"> <DataTemplate DataType="{x:Type dialogs:ModelVersionViewModel}">
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
MinWidth="128" MinWidth="128"
Margin="-24,4,0,4"> Margin="0,4,0,4">
<fluentAvalonia:SymbolIcon Symbol="Checkmark" <fluentAvalonia:SymbolIcon Symbol="Checkmark"
Foreground="Lime" Foreground="Lime"
IsVisible="{Binding IsInstalled}" IsVisible="{Binding IsInstalled}"
VerticalAlignment="Center"/> VerticalAlignment="Center" />
<TextBlock Margin="8, 0" <TextBlock Margin="4, 0"
Padding="4" Padding="4"
Text="{Binding ModelVersion.Name}" /> Text="{Binding ModelVersion.Name}" />
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</TreeView.ItemTemplate> </ListBox.ItemTemplate>
</TreeView> <ListBox.Template>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
</ListBox>
<TreeView Grid.Row="0" Grid.Column="2" <ListBox Grid.Row="0" Grid.Column="2"
Margin="8"
ItemsSource="{Binding SelectedVersionViewModel.CivitFileViewModels}" ItemsSource="{Binding SelectedVersionViewModel.CivitFileViewModels}"
SelectedItem="{Binding SelectedFile}"> SelectedItem="{Binding SelectedFile}">
<TreeView.ItemTemplate> <ListBox.Template>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter Margin="8" />
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type dialogs:CivitFileViewModel}"> <DataTemplate DataType="{x:Type dialogs:CivitFileViewModel}">
<StackPanel Orientation="Horizontal" Margin="-24, 4, 4, 4"> <Grid RowDefinitions="Auto, Auto" ColumnDefinitions="Auto, *"
<fluentAvalonia:SymbolIcon Symbol="Checkmark" Margin="-4,0,0,0">
<fluentAvalonia:SymbolIcon Grid.Row="0" Grid.RowSpan="2"
Grid.Column="0"
Margin="0, 0, 8, 0"
Symbol="Checkmark"
Foreground="Lime" Foreground="Lime"
IsVisible="{Binding IsInstalled}" IsVisible="{Binding IsInstalled}"
VerticalAlignment="Center"/> VerticalAlignment="Center" />
<StackPanel Margin="8,0" VerticalAlignment="Top"> <TextBlock Grid.Row="0" Grid.Column="1"
<TextBlock Margin="4,4,0,4" Text="{Binding CivitFile.Name}" /> Text="{Binding CivitFile.Name}"
<TextBlock Margin="0,0,0,4" FontSize="11"> Margin="0, 4, 0, 4"
TextWrapping="Wrap" />
<TextBlock Grid.Row="1" Grid.Column="1"
FontSize="11"
Margin="0, 4, 0, 4"
TextWrapping="Wrap">
<Run Text="{Binding CivitFile.Metadata.Format}" />
<Run Text="-" />
<Run Text="{Binding CivitFile.Metadata.Size}" /> <Run Text="{Binding CivitFile.Metadata.Size}" />
<Run Text="-" />
<Run Text="{Binding CivitFile.Metadata.Fp}" /> <Run Text="{Binding CivitFile.Metadata.Fp}" />
<Run Text="-" /> <Run Text="-" />
<Run Text="{Binding CivitFile.FullFilesSize, Mode=OneWay}" /> <Run Text="{Binding CivitFile.FullFilesSize, Mode=OneWay}" />
</TextBlock> </TextBlock>
</StackPanel> </Grid>
</StackPanel>
</DataTemplate> </DataTemplate>
</TreeView.ItemTemplate> </ListBox.ItemTemplate>
</TreeView> </ListBox>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" <StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1"
Orientation="Horizontal" Orientation="Horizontal"
@ -81,14 +105,14 @@
Content="Cancel" Content="Cancel"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Command="{Binding Cancel}" Command="{Binding Cancel}"
Margin="8, 0"/> Margin="8, 0" />
<Button <Button
Margin="8, 0" Margin="8, 0"
Content="Import" Content="Import"
Command="{Binding Import}" Command="{Binding Import}"
IsEnabled="{Binding IsImportEnabled}" IsEnabled="{Binding IsImportEnabled}"
Classes="accent"/> Classes="accent" />
</StackPanel> </StackPanel>
</Grid> </Grid>

2
StabilityMatrix.Avalonia/Views/MainWindow.axaml

@ -111,7 +111,7 @@
IsVisible="{Binding !!ProgressItems.Count}" IsVisible="{Binding !!ProgressItems.Count}"
Tapped="FooterDownloadItem_OnTapped"> Tapped="FooterDownloadItem_OnTapped">
<ui:NavigationViewItem.ContextFlyout> <ui:NavigationViewItem.ContextFlyout>
<controls:BetterFlyout Placement="Right" <controls:BetterFlyout Placement="RightEdgeAlignedBottom"
HorizontalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
Content="{Binding }" /> Content="{Binding }" />

Loading…
Cancel
Save