Browse Source

UI fixes for license dialog freeze due to size

pull/5/head
Ionite 1 year ago
parent
commit
975cefc87d
No known key found for this signature in database
  1. 8
      StabilityMatrix/CheckpointManagerPage.xaml
  2. 3
      StabilityMatrix/Database/ILiteDbContext.cs
  3. 22
      StabilityMatrix/Database/LiteDbContext.cs
  4. 5
      StabilityMatrix/MainWindow.xaml
  5. 50
      StabilityMatrix/ViewModels/SettingsViewModel.cs

8
StabilityMatrix/CheckpointManagerPage.xaml

@ -9,6 +9,7 @@
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
x:Class="StabilityMatrix.CheckpointManagerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:StabilityMatrix.Controls"
xmlns:converters="clr-namespace:StabilityMatrix.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:designData="clr-namespace:StabilityMatrix.DesignData"
@ -342,9 +343,9 @@
IsIndeterminate="{Binding Progress.IsIndeterminate, FallbackValue=False}"
Margin="64,8"
Name="ImportProgressBar"
Value="{Binding Progress.Value, FallbackValue=20}"
VerticalAlignment="Center"
Visibility="{Binding Progress.ProgressVisibility, FallbackValue=Visible}" />
Visibility="{Binding Progress.ProgressVisibility, FallbackValue=Visible}"
controls:ProgressBarSmoother.SmoothValue="{Binding Progress.Value, FallbackValue=20}" />
</VirtualizingStackPanel>
</Grid>
</Expander>
@ -423,8 +424,9 @@
Margin="16,0"
Orientation="Horizontal">
<ComboBox
HorizontalAlignment="Right"
ItemsSource="{Binding CheckpointFolders}"
MinWidth="150"
MinWidth="180"
SelectedIndex="0">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">

3
StabilityMatrix/Database/ILiteDbContext.cs

@ -13,7 +13,8 @@ public interface ILiteDbContext : IDisposable
ILiteCollectionAsync<CivitModel> CivitModels { get; }
ILiteCollectionAsync<CivitModelVersion> CivitModelVersions { get; }
ILiteCollectionAsync<CivitModelQueryCacheEntry> CivitModelQueryCache { get; }
Task<(CivitModel?, CivitModelVersion?)> FindCivitModelFromFileHashAsync(string hashBlake3);
Task<bool> UpsertCivitModelAsync(CivitModel civitModel);
Task<bool> UpsertCivitModelAsync(IEnumerable<CivitModel> civitModels);
Task<bool> UpsertCivitModelQueryCacheEntryAsync(CivitModelQueryCacheEntry entry);

22
StabilityMatrix/Database/LiteDbContext.cs

@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using LiteDB;
using LiteDB.Async;
using StabilityMatrix.Extensions;
using StabilityMatrix.Models.Api;
@ -24,10 +27,29 @@ public class LiteDbContext : ILiteDbContext
{
Database = new LiteDatabaseAsync(connectionString);
// Register reference fields
LiteDBExtensions.Register<CivitModel, CivitModelVersion>(m => m.ModelVersions, "CivitModelVersions");
LiteDBExtensions.Register<CivitModelQueryCacheEntry, CivitModel>(e => e.Items, "CivitModels");
}
public async Task<(CivitModel?, CivitModelVersion?)> FindCivitModelFromFileHashAsync(string hashBlake3)
{
var version = await CivitModelVersions.Query()
.Where(mv => mv.Files!
.Select(f => f.Hashes)
.Select(hashes => hashes.BLAKE3)
.Any(hash => hash == hashBlake3))
.FirstOrDefaultAsync();
if (version is null) return (null, null);
var model = await CivitModels.Query()
.Include(m => m.ModelVersions)
.Where(m => m.ModelVersions!
.Select(v => v.Id)
.Any(id => id == version.Id))
.FirstOrDefaultAsync();
return (model, version);
}
public async Task<bool> UpsertCivitModelAsync(CivitModel civitModel)
{
// Insert model versions first then model

5
StabilityMatrix/MainWindow.xaml

@ -2,12 +2,12 @@
Closed="MainWindow_OnClosed"
ExtendsContentIntoTitleBar="True"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Height="750"
Height="900"
Icon="pack://application:,,,/Assets/Icon.ico"
Loaded="MainWindow_OnLoaded"
Title="Stability Matrix"
UseLayoutRounding="True"
Width="1100"
Width="1300"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen"
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel,
@ -62,6 +62,7 @@
<Grid Grid.Row="1">
<ui:NavigationView
IsBackButtonVisible="Collapsed"
OpenPaneLength="260"
PaneClosed="RootNavigation_OnPaneClosed"
PaneOpened="RootNavigation_OnPaneOpened"
UseLayoutRounding="True"

50
StabilityMatrix/ViewModels/SettingsViewModel.cs

@ -227,45 +227,35 @@ public partial class SettingsViewModel : ObservableObject
var fileHash = await FileHash.GetBlake3Async(path, progress);
var timeTakenHash = timer.Elapsed.TotalSeconds;
IsFileSearchFlyoutOpen = false;
// Search for file
timer.Restart();
var (model, version) =
await liteDbContext.FindCivitModelFromFileHashAsync(fileHash);
timer.Stop();
var timeTakenSearch = timer.Elapsed.TotalMilliseconds;
var generalText =
$"Time taken to hash: {timeTakenHash:F2} s\n" +
$"Time taken to search: {timeTakenSearch:F1} ms\n";
var modelVersion = await liteDbContext.CivitModelVersions.Query()
.Where(mv => mv.Files!
.Select(f => f.Hashes)
.Select(hashes => hashes.BLAKE3)
.Any(hash => hash == fileHash))
.FirstOrDefaultAsync();
var model = modelVersion != null
? await liteDbContext.CivitModels.Query()
.Include(m => m.ModelVersions)
.Where(m => m.ModelVersions!
.Select(v => v.Id)
.Any(id => id == modelVersion.Id))
.FirstOrDefaultAsync() : null;
timer.Stop();
var timeTakenSearch = timer.Elapsed.TotalSeconds;
// Not found
if (model == null)
{
var dialog = contentDialogService.CreateDialog();
dialog.Title = "Model file search";
dialog.Content = $"File not found in database. Hash: {fileHash}\n" +
$"Time taken to hash: {timeTakenHash:F1} s\n" +
$"Time taken to search: {timeTakenSearch:F1} s";
dialog.Title = "Model not found :(";
dialog.Content = $"File not found in database. Hash: {fileHash}\n" + generalText;
await dialog.ShowAsync();
}
else
{
// Found
var dialog = contentDialogService.CreateDialog();
dialog.Title = "Model file search";
dialog.Title = "Model found!";
dialog.Content = $"File found in database. Hash: {fileHash}\n" +
$"Model: {model.Name}\n" +
$"Version: {modelVersion.Name}\n" +
$"Time taken to hash: {timeTakenHash:F1} s\n" +
$"Time taken to search: {timeTakenSearch:F1} s";
$"Version: {version!.Name}\n" + generalText;
await dialog.ShowAsync();
}
}
@ -336,19 +326,25 @@ public partial class SettingsViewModel : ObservableObject
return;
}
var flowViewer = new FlowDocumentScrollViewer();
var flowViewer = new FlowDocumentScrollViewer
{
MaxHeight = 400,
MaxWidth = 600,
};
var markdownText = "";
foreach (var license in licenses)
{
markdownText += $"## [{license.PackageName}]({license.PackageUrl}) by {string.Join(", ", license.Authors)}\n\n";
markdownText += $"## [**{license.PackageName}**]({license.PackageUrl}) by {string.Join(", ", license.Authors)}\n\n";
markdownText += $"{license.Copyright}\n\n";
markdownText += $"[{license.LicenseUrl}]({license.LicenseUrl})\n\n";
}
flowViewer.Document = TextToFlowDocumentConverter!.Convert(markdownText, typeof(FlowDocument), null, CultureInfo.CurrentCulture) as FlowDocument;
flowViewer.Document = TextToFlowDocumentConverter!.Convert(markdownText, typeof(FlowDocument), null!, CultureInfo.CurrentCulture) as FlowDocument;
var dialog = contentDialogService.CreateDialog();
dialog.Title = "License and Open Source Notices";
dialog.Content = flowViewer;
dialog.DialogMaxHeight = 1000;
dialog.DialogMaxWidth = 900;
dialog.IsPrimaryButtonEnabled = false;
await dialog.ShowAsync();
}

Loading…
Cancel
Save