Skip to content

Commit

Permalink
Merge pull request LykosAI#909 from ionite34/backport/main/pr-899
Browse files Browse the repository at this point in the history
[dev to main] backport: O B S E R V E (899)
  • Loading branch information
mohnjiles authored Dec 5, 2024
2 parents 922a68a + bdf423d commit 5f6d792
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 28 deletions.
17 changes: 6 additions & 11 deletions StabilityMatrix.Avalonia/Behaviors/TextEditorToolTipBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
Expand Down Expand Up @@ -29,9 +31,7 @@ public class TextEditorToolTipBehavior : Behavior<TextEditor>
private ToolTip? toolTip;

public static readonly StyledProperty<ITokenizerProvider?> TokenizerProviderProperty =
AvaloniaProperty.Register<TextEditorCompletionBehavior, ITokenizerProvider?>(
"TokenizerProvider"
);
AvaloniaProperty.Register<TextEditorCompletionBehavior, ITokenizerProvider?>("TokenizerProvider");

public ITokenizerProvider? TokenizerProvider
{
Expand Down Expand Up @@ -137,6 +137,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)

toolTip
.GetPropertyChangedObservable(ToolTip.IsOpenProperty)
.ObserveOn(SynchronizationContext.Current)
.Subscribe(c =>
{
if (c.NewValue as bool? != true)
Expand All @@ -159,10 +160,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)
private ToolTipData? GetCaretToolTipData(TextViewPosition position)
{
var logicalPosition = position.Location;
var pointerOffset = textEditor.Document.GetOffset(
logicalPosition.Line,
logicalPosition.Column
);
var pointerOffset = textEditor.Document.GetOffset(logicalPosition.Line, logicalPosition.Column);

var line = textEditor.Document.GetLineByOffset(pointerOffset);
var lineText = textEditor.Document.GetText(line.Offset, line.Length);
Expand Down Expand Up @@ -227,10 +225,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)
if (result.Tokens.ElementAtOrDefault(currentTokenIndex + tokenOffset) is { } token)
{
// Check supported scopes
if (
token.Scopes.Where(s => s.Contains("invalid")).ToArray() is
{ Length: > 0 } results
)
if (token.Scopes.Where(s => s.Contains("invalid")).ToArray() is { Length: > 0 } results)
{
// Special cases
if (results.Contains("invalid.illegal.mismatched.parenthesis.closing.prompt"))
Expand Down
3 changes: 3 additions & 0 deletions StabilityMatrix.Avalonia/Collections/SearchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using DynamicData;
using DynamicData.Binding;
using JetBrains.Annotations;
Expand Down Expand Up @@ -72,6 +73,7 @@ public SearchCollection(
.Filter(dynamicPredicate)
.Sort(SortComparer)
.Bind(FilteredItems)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();
}

Expand Down Expand Up @@ -114,6 +116,7 @@ public SearchCollection(
.Sort(SearchItemSortComparer, SortOptimisations.ComparesImmutableValuesOnly)
.Transform(searchItem => searchItem.Item)
.Bind(FilteredItems)
.ObserveOn(SynchronizationContext.Current)
.Subscribe()
);
}
Expand Down
5 changes: 4 additions & 1 deletion StabilityMatrix.Avalonia/Controls/BetterComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
Expand Down Expand Up @@ -48,7 +49,9 @@ public BetterComboBox()
.Select(_ => currentInput);

// Subscribe to the observable to filter the ComboBox items
subscription = inputObservable.Subscribe(OnInputReceived, _ => ResetPopupText());
subscription = inputObservable
.ObserveOn(SynchronizationContext.Current)
.Subscribe(OnInputReceived, _ => ResetPopupText());

// Initialize the popup
inputPopup = new Popup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Reactive.Linq;
using System.Threading;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using DynamicData.Binding;
Expand All @@ -24,6 +26,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

imageControl
.WhenPropertyChanged(x => x.CurrentImage)
.ObserveOn(SynchronizationContext.Current)
.Subscribe(propertyValue =>
{
if (propertyValue.Value is { } image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -108,6 +110,7 @@ protected override void OnDataContextChanged(EventArgs e)
viewModelSubscription?.Dispose();
viewModelSubscription = viewModel
.WhenPropertyChanged(vm => vm.CanvasSize)
.ObserveOn(SynchronizationContext.Current)
.Subscribe(change =>
{
if (MainCanvas is not null && !change.Value.IsEmpty)
Expand Down
38 changes: 34 additions & 4 deletions StabilityMatrix.Avalonia/Services/InferenceClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
Expand Down Expand Up @@ -164,6 +165,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(Models)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

controlNetModelsSource
Expand All @@ -176,6 +178,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(ControlNetModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

loraModelsSource
Expand All @@ -185,6 +188,7 @@ ICompletionProvider completionProvider
LoraModels,
SortExpressionComparer<HybridModelFile>.Ascending(f => f.Type).ThenByAscending(f => f.SortKey)
)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

promptExpansionModelsSource
Expand All @@ -197,6 +201,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(PromptExpansionModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

ultralyticsModelsSource
Expand All @@ -209,6 +214,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(UltralyticsModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

samModelsSource
Expand All @@ -221,6 +227,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(SamModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

unetModelsSource
Expand All @@ -232,6 +239,7 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(UnetModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

clipModelsSource
Expand All @@ -244,25 +252,47 @@ ICompletionProvider completionProvider
)
.DeferUntilLoaded()
.Bind(ClipModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

vaeModelsDefaults.AddOrUpdate(HybridModelFile.Default);

vaeModelsDefaults.Connect().Or(vaeModelsSource.Connect()).Bind(VaeModels).Subscribe();
vaeModelsDefaults
.Connect()
.Or(vaeModelsSource.Connect())
.Bind(VaeModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

samplersSource.Connect().DeferUntilLoaded().Bind(Samplers).Subscribe();
samplersSource
.Connect()
.DeferUntilLoaded()
.Bind(Samplers)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

latentUpscalersSource
.Connect()
.Or(modelUpscalersSource.Connect())
.Or(downloadableUpscalersSource.Connect())
.Sort(SortExpressionComparer<ComfyUpscaler>.Ascending(f => f.Type).ThenByAscending(f => f.Name))
.Bind(Upscalers)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

schedulersSource.Connect().DeferUntilLoaded().Bind(Schedulers).Subscribe();
schedulersSource
.Connect()
.DeferUntilLoaded()
.Bind(Schedulers)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

preprocessorsSource.Connect().DeferUntilLoaded().Bind(Preprocessors).Subscribe();
preprocessorsSource
.Connect()
.DeferUntilLoaded()
.Bind(Preprocessors)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

settingsManager.RegisterOnLibraryDirSet(_ =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Http;
using System.Reactive.Linq;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls;
Expand Down Expand Up @@ -146,6 +147,7 @@ or nameof(HideEarlyAccessModels)
.Throttle(TimeSpan.FromMilliseconds(50))
.Select(_ => (Func<CheckpointBrowserCardViewModel, bool>)FilterModelCardsPredicate)
.StartWith(FilterModelCardsPredicate)
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

var sortPredicate = SortExpressionComparer<CheckpointBrowserCardViewModel>.Ascending(
Expand All @@ -167,9 +169,15 @@ or nameof(HideEarlyAccessModels)
.DisposeMany()
.Filter(filterPredicate)
.SortAndBind(ModelCards, sortPredicate)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

baseModelCache.Connect().DeferUntilLoaded().SortAndBind(AllBaseModels).Subscribe();
baseModelCache
.Connect()
.DeferUntilLoaded()
.SortAndBind(AllBaseModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

baseModelCache.AddOrUpdate(Enum.GetValues<CivitBaseModelType>().Select(t => t.GetStringValue()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reactive.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
Expand Down Expand Up @@ -86,6 +87,7 @@ INotificationService notificationService
.Bind(Categories)
.WhenAnyPropertyChanged()
.Throttle(TimeSpan.FromMilliseconds(50))
.ObserveOn(SynchronizationContext.Current)
.Subscribe(_ => NumSelected = Categories.Sum(c => c.NumSelected));

progressTimer.Tick += (_, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Controls;
Expand Down Expand Up @@ -196,6 +197,7 @@ protected override void OnInitialLoaded()
)
)
)
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

var filterPredicate = Observable
Expand All @@ -209,6 +211,7 @@ or nameof(SelectedBaseModels)
)
.Throttle(TimeSpan.FromMilliseconds(50))
.Select(_ => (Func<LocalModelFile, bool>)FilterModels)
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

var comparerObservable = Observable
Expand Down Expand Up @@ -282,6 +285,7 @@ or nameof(SortConnectedModelsFirst)

return comparer;
})
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

ModelsCache
Expand All @@ -304,6 +308,7 @@ or nameof(SortConnectedModelsFirst)
.SortAndBind(Models, comparerObservable)
.WhenPropertyChanged(p => p.IsSelected)
.Throttle(TimeSpan.FromMilliseconds(50))
.ObserveOn(SynchronizationContext.Current)
.Subscribe(_ =>
{
NumItemsSelected = Models.Count(o => o.IsSelected);
Expand All @@ -315,6 +320,7 @@ or nameof(SortConnectedModelsFirst)
.Throttle(TimeSpan.FromMilliseconds(50))
.Select(_ => (Func<CheckpointCategory, bool>)FilterCategories)
.StartWith(FilterCategories)
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

categoriesCache
Expand All @@ -327,6 +333,7 @@ or nameof(SortConnectedModelsFirst)
.Descending(x => x.Name == "All Models")
.ThenByAscending(x => x.Name)
)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

settingsManager.RelayPropertyFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using Avalonia.Threading;
Expand Down Expand Up @@ -70,6 +71,7 @@ INotificationService notificationService

var incompatiblePredicate = this.WhenPropertyChanged(vm => vm.ShowIncompatiblePackages)
.Select(_ => new Func<BasePackage, bool>(p => p.IsCompatible || ShowIncompatiblePackages))
.ObserveOn(SynchronizationContext.Current)
.AsObservable();

AllPackagesCache
Expand All @@ -83,6 +85,7 @@ INotificationService notificationService
.Ascending(p => p.InstallerSortOrder)
.ThenByAscending(p => p.DisplayName)
)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

AllPackagesCache.AddOrUpdate(packageFactory.GetAllAvailablePackages());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
Expand Down Expand Up @@ -73,13 +75,15 @@ IModelImportService modelImportService
.DeferUntilLoaded()
.Filter(f => f.ModelVersion.BaseModel == "SD 1.5")
.Bind(Sd15Models)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();

CivitModels
.Connect()
.DeferUntilLoaded()
.Filter(f => f.ModelVersion.BaseModel == "SDXL 1.0" || f.ModelVersion.BaseModel == "Pony")
.Bind(SdxlModels)
.ObserveOn(SynchronizationContext.Current)
.Subscribe();
}

Expand Down
Loading

0 comments on commit 5f6d792

Please sign in to comment.