Skip to content

Commit 5f6d792

Browse files
authored
Merge pull request #909 from ionite34/backport/main/pr-899
[dev to main] backport: O B S E R V E (899)
2 parents 922a68a + bdf423d commit 5f6d792

23 files changed

+127
-28
lines changed

StabilityMatrix.Avalonia/Behaviors/TextEditorToolTipBehavior.cs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Linq;
4+
using System.Reactive.Linq;
5+
using System.Threading;
46
using Avalonia;
57
using Avalonia.Controls;
68
using Avalonia.Input;
@@ -29,9 +31,7 @@ public class TextEditorToolTipBehavior : Behavior<TextEditor>
2931
private ToolTip? toolTip;
3032

3133
public static readonly StyledProperty<ITokenizerProvider?> TokenizerProviderProperty =
32-
AvaloniaProperty.Register<TextEditorCompletionBehavior, ITokenizerProvider?>(
33-
"TokenizerProvider"
34-
);
34+
AvaloniaProperty.Register<TextEditorCompletionBehavior, ITokenizerProvider?>("TokenizerProvider");
3535

3636
public ITokenizerProvider? TokenizerProvider
3737
{
@@ -137,6 +137,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)
137137

138138
toolTip
139139
.GetPropertyChangedObservable(ToolTip.IsOpenProperty)
140+
.ObserveOn(SynchronizationContext.Current)
140141
.Subscribe(c =>
141142
{
142143
if (c.NewValue as bool? != true)
@@ -159,10 +160,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)
159160
private ToolTipData? GetCaretToolTipData(TextViewPosition position)
160161
{
161162
var logicalPosition = position.Location;
162-
var pointerOffset = textEditor.Document.GetOffset(
163-
logicalPosition.Line,
164-
logicalPosition.Column
165-
);
163+
var pointerOffset = textEditor.Document.GetOffset(logicalPosition.Line, logicalPosition.Column);
166164

167165
var line = textEditor.Document.GetLineByOffset(pointerOffset);
168166
var lineText = textEditor.Document.GetText(line.Offset, line.Length);
@@ -227,10 +225,7 @@ private void TextEditor_OnPointerHover(object? sender, PointerEventArgs e)
227225
if (result.Tokens.ElementAtOrDefault(currentTokenIndex + tokenOffset) is { } token)
228226
{
229227
// Check supported scopes
230-
if (
231-
token.Scopes.Where(s => s.Contains("invalid")).ToArray() is
232-
{ Length: > 0 } results
233-
)
228+
if (token.Scopes.Where(s => s.Contains("invalid")).ToArray() is { Length: > 0 } results)
234229
{
235230
// Special cases
236231
if (results.Contains("invalid.illegal.mismatched.parenthesis.closing.prompt"))

StabilityMatrix.Avalonia/Collections/SearchCollection.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Reactive.Disposables;
55
using System.Reactive.Linq;
6+
using System.Threading;
67
using DynamicData;
78
using DynamicData.Binding;
89
using JetBrains.Annotations;
@@ -72,6 +73,7 @@ public SearchCollection(
7273
.Filter(dynamicPredicate)
7374
.Sort(SortComparer)
7475
.Bind(FilteredItems)
76+
.ObserveOn(SynchronizationContext.Current)
7577
.Subscribe();
7678
}
7779

@@ -114,6 +116,7 @@ public SearchCollection(
114116
.Sort(SearchItemSortComparer, SortOptimisations.ComparesImmutableValuesOnly)
115117
.Transform(searchItem => searchItem.Item)
116118
.Bind(FilteredItems)
119+
.ObserveOn(SynchronizationContext.Current)
117120
.Subscribe()
118121
);
119122
}

StabilityMatrix.Avalonia/Controls/BetterComboBox.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Reactive.Linq;
44
using System.Reactive.Subjects;
5+
using System.Threading;
56
using Avalonia;
67
using Avalonia.Controls;
78
using Avalonia.Controls.Presenters;
@@ -48,7 +49,9 @@ public BetterComboBox()
4849
.Select(_ => currentInput);
4950

5051
// Subscribe to the observable to filter the ComboBox items
51-
subscription = inputObservable.Subscribe(OnInputReceived, _ => ResetPopupText());
52+
subscription = inputObservable
53+
.ObserveOn(SynchronizationContext.Current)
54+
.Subscribe(OnInputReceived, _ => ResetPopupText());
5255

5356
// Initialize the popup
5457
inputPopup = new Popup

StabilityMatrix.Avalonia/Controls/Inference/SelectImageCard.axaml.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Reactive.Linq;
3+
using System.Threading;
24
using Avalonia.Controls;
35
using Avalonia.Controls.Primitives;
46
using DynamicData.Binding;
@@ -24,6 +26,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
2426

2527
imageControl
2628
.WhenPropertyChanged(x => x.CurrentImage)
29+
.ObserveOn(SynchronizationContext.Current)
2730
.Subscribe(propertyValue =>
2831
{
2932
if (propertyValue.Value is { } image)

StabilityMatrix.Avalonia/Controls/Painting/PaintCanvas.axaml.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Collections.Immutable;
44
using System.Diagnostics;
55
using System.Linq;
6+
using System.Reactive.Linq;
7+
using System.Threading;
68
using System.Threading.Tasks;
79
using Avalonia;
810
using Avalonia.Controls;
@@ -108,6 +110,7 @@ protected override void OnDataContextChanged(EventArgs e)
108110
viewModelSubscription?.Dispose();
109111
viewModelSubscription = viewModel
110112
.WhenPropertyChanged(vm => vm.CanvasSize)
113+
.ObserveOn(SynchronizationContext.Current)
111114
.Subscribe(change =>
112115
{
113116
if (MainCanvas is not null && !change.Value.IsEmpty)

StabilityMatrix.Avalonia/Services/InferenceClientManager.cs

+34-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics.CodeAnalysis;
44
using System.IO;
55
using System.Linq;
6+
using System.Reactive.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using AsyncAwaitBestPractices;
@@ -164,6 +165,7 @@ ICompletionProvider completionProvider
164165
)
165166
.DeferUntilLoaded()
166167
.Bind(Models)
168+
.ObserveOn(SynchronizationContext.Current)
167169
.Subscribe();
168170

169171
controlNetModelsSource
@@ -176,6 +178,7 @@ ICompletionProvider completionProvider
176178
)
177179
.DeferUntilLoaded()
178180
.Bind(ControlNetModels)
181+
.ObserveOn(SynchronizationContext.Current)
179182
.Subscribe();
180183

181184
loraModelsSource
@@ -185,6 +188,7 @@ ICompletionProvider completionProvider
185188
LoraModels,
186189
SortExpressionComparer<HybridModelFile>.Ascending(f => f.Type).ThenByAscending(f => f.SortKey)
187190
)
191+
.ObserveOn(SynchronizationContext.Current)
188192
.Subscribe();
189193

190194
promptExpansionModelsSource
@@ -197,6 +201,7 @@ ICompletionProvider completionProvider
197201
)
198202
.DeferUntilLoaded()
199203
.Bind(PromptExpansionModels)
204+
.ObserveOn(SynchronizationContext.Current)
200205
.Subscribe();
201206

202207
ultralyticsModelsSource
@@ -209,6 +214,7 @@ ICompletionProvider completionProvider
209214
)
210215
.DeferUntilLoaded()
211216
.Bind(UltralyticsModels)
217+
.ObserveOn(SynchronizationContext.Current)
212218
.Subscribe();
213219

214220
samModelsSource
@@ -221,6 +227,7 @@ ICompletionProvider completionProvider
221227
)
222228
.DeferUntilLoaded()
223229
.Bind(SamModels)
230+
.ObserveOn(SynchronizationContext.Current)
224231
.Subscribe();
225232

226233
unetModelsSource
@@ -232,6 +239,7 @@ ICompletionProvider completionProvider
232239
)
233240
.DeferUntilLoaded()
234241
.Bind(UnetModels)
242+
.ObserveOn(SynchronizationContext.Current)
235243
.Subscribe();
236244

237245
clipModelsSource
@@ -244,25 +252,47 @@ ICompletionProvider completionProvider
244252
)
245253
.DeferUntilLoaded()
246254
.Bind(ClipModels)
255+
.ObserveOn(SynchronizationContext.Current)
247256
.Subscribe();
248257

249258
vaeModelsDefaults.AddOrUpdate(HybridModelFile.Default);
250259

251-
vaeModelsDefaults.Connect().Or(vaeModelsSource.Connect()).Bind(VaeModels).Subscribe();
260+
vaeModelsDefaults
261+
.Connect()
262+
.Or(vaeModelsSource.Connect())
263+
.Bind(VaeModels)
264+
.ObserveOn(SynchronizationContext.Current)
265+
.Subscribe();
252266

253-
samplersSource.Connect().DeferUntilLoaded().Bind(Samplers).Subscribe();
267+
samplersSource
268+
.Connect()
269+
.DeferUntilLoaded()
270+
.Bind(Samplers)
271+
.ObserveOn(SynchronizationContext.Current)
272+
.Subscribe();
254273

255274
latentUpscalersSource
256275
.Connect()
257276
.Or(modelUpscalersSource.Connect())
258277
.Or(downloadableUpscalersSource.Connect())
259278
.Sort(SortExpressionComparer<ComfyUpscaler>.Ascending(f => f.Type).ThenByAscending(f => f.Name))
260279
.Bind(Upscalers)
280+
.ObserveOn(SynchronizationContext.Current)
261281
.Subscribe();
262282

263-
schedulersSource.Connect().DeferUntilLoaded().Bind(Schedulers).Subscribe();
283+
schedulersSource
284+
.Connect()
285+
.DeferUntilLoaded()
286+
.Bind(Schedulers)
287+
.ObserveOn(SynchronizationContext.Current)
288+
.Subscribe();
264289

265-
preprocessorsSource.Connect().DeferUntilLoaded().Bind(Preprocessors).Subscribe();
290+
preprocessorsSource
291+
.Connect()
292+
.DeferUntilLoaded()
293+
.Bind(Preprocessors)
294+
.ObserveOn(SynchronizationContext.Current)
295+
.Subscribe();
266296

267297
settingsManager.RegisterOnLibraryDirSet(_ =>
268298
{

StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CivitAiBrowserViewModel.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net.Http;
77
using System.Reactive.Linq;
88
using System.Text.Json.Nodes;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using AsyncAwaitBestPractices;
1112
using Avalonia.Controls;
@@ -146,6 +147,7 @@ or nameof(HideEarlyAccessModels)
146147
.Throttle(TimeSpan.FromMilliseconds(50))
147148
.Select(_ => (Func<CheckpointBrowserCardViewModel, bool>)FilterModelCardsPredicate)
148149
.StartWith(FilterModelCardsPredicate)
150+
.ObserveOn(SynchronizationContext.Current)
149151
.AsObservable();
150152

151153
var sortPredicate = SortExpressionComparer<CheckpointBrowserCardViewModel>.Ascending(
@@ -167,9 +169,15 @@ or nameof(HideEarlyAccessModels)
167169
.DisposeMany()
168170
.Filter(filterPredicate)
169171
.SortAndBind(ModelCards, sortPredicate)
172+
.ObserveOn(SynchronizationContext.Current)
170173
.Subscribe();
171174

172-
baseModelCache.Connect().DeferUntilLoaded().SortAndBind(AllBaseModels).Subscribe();
175+
baseModelCache
176+
.Connect()
177+
.DeferUntilLoaded()
178+
.SortAndBind(AllBaseModels)
179+
.ObserveOn(SynchronizationContext.Current)
180+
.Subscribe();
173181

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

StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/HuggingFacePageViewModel.cs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reactive.Linq;
77
using System.Text.Json;
88
using System.Text.Json.Serialization;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using Avalonia.Controls;
1112
using Avalonia.Controls.Notifications;
@@ -86,6 +87,7 @@ INotificationService notificationService
8687
.Bind(Categories)
8788
.WhenAnyPropertyChanged()
8889
.Throttle(TimeSpan.FromMilliseconds(50))
90+
.ObserveOn(SynchronizationContext.Current)
8991
.Subscribe(_ => NumSelected = Categories.Sum(c => c.NumSelected));
9092

9193
progressTimer.Tick += (_, _) =>

StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Reactive.Linq;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using AsyncAwaitBestPractices;
1112
using Avalonia.Controls;
@@ -196,6 +197,7 @@ protected override void OnInitialLoaded()
196197
)
197198
)
198199
)
200+
.ObserveOn(SynchronizationContext.Current)
199201
.AsObservable();
200202

201203
var filterPredicate = Observable
@@ -209,6 +211,7 @@ or nameof(SelectedBaseModels)
209211
)
210212
.Throttle(TimeSpan.FromMilliseconds(50))
211213
.Select(_ => (Func<LocalModelFile, bool>)FilterModels)
214+
.ObserveOn(SynchronizationContext.Current)
212215
.AsObservable();
213216

214217
var comparerObservable = Observable
@@ -282,6 +285,7 @@ or nameof(SortConnectedModelsFirst)
282285

283286
return comparer;
284287
})
288+
.ObserveOn(SynchronizationContext.Current)
285289
.AsObservable();
286290

287291
ModelsCache
@@ -304,6 +308,7 @@ or nameof(SortConnectedModelsFirst)
304308
.SortAndBind(Models, comparerObservable)
305309
.WhenPropertyChanged(p => p.IsSelected)
306310
.Throttle(TimeSpan.FromMilliseconds(50))
311+
.ObserveOn(SynchronizationContext.Current)
307312
.Subscribe(_ =>
308313
{
309314
NumItemsSelected = Models.Count(o => o.IsSelected);
@@ -315,6 +320,7 @@ or nameof(SortConnectedModelsFirst)
315320
.Throttle(TimeSpan.FromMilliseconds(50))
316321
.Select(_ => (Func<CheckpointCategory, bool>)FilterCategories)
317322
.StartWith(FilterCategories)
323+
.ObserveOn(SynchronizationContext.Current)
318324
.AsObservable();
319325

320326
categoriesCache
@@ -327,6 +333,7 @@ or nameof(SortConnectedModelsFirst)
327333
.Descending(x => x.Name == "All Models")
328334
.ThenByAscending(x => x.Name)
329335
)
336+
.ObserveOn(SynchronizationContext.Current)
330337
.Subscribe();
331338

332339
settingsManager.RelayPropertyFor(

StabilityMatrix.Avalonia/ViewModels/Dialogs/NewOneClickInstallViewModel.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reactive.Linq;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using AsyncAwaitBestPractices;
89
using Avalonia.Threading;
@@ -70,6 +71,7 @@ INotificationService notificationService
7071

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

7577
AllPackagesCache
@@ -83,6 +85,7 @@ INotificationService notificationService
8385
.Ascending(p => p.InstallerSortOrder)
8486
.ThenByAscending(p => p.DisplayName)
8587
)
88+
.ObserveOn(SynchronizationContext.Current)
8689
.Subscribe();
8790

8891
AllPackagesCache.AddOrUpdate(packageFactory.GetAllAvailablePackages());

StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.IO;
33
using System.Linq;
4+
using System.Reactive.Linq;
5+
using System.Threading;
46
using System.Threading.Tasks;
57
using Avalonia.Controls;
68
using CommunityToolkit.Mvvm.ComponentModel;
@@ -73,13 +75,15 @@ IModelImportService modelImportService
7375
.DeferUntilLoaded()
7476
.Filter(f => f.ModelVersion.BaseModel == "SD 1.5")
7577
.Bind(Sd15Models)
78+
.ObserveOn(SynchronizationContext.Current)
7679
.Subscribe();
7780

7881
CivitModels
7982
.Connect()
8083
.DeferUntilLoaded()
8184
.Filter(f => f.ModelVersion.BaseModel == "SDXL 1.0" || f.ModelVersion.BaseModel == "Pony")
8285
.Bind(SdxlModels)
86+
.ObserveOn(SynchronizationContext.Current)
8387
.Subscribe();
8488
}
8589

0 commit comments

Comments
 (0)