@@ -55,6 +55,11 @@ [ObservableProperty] [NotifyPropertyChangedFor(nameof(IsUiEnabled))]
5555
5656 [ ObservableProperty ]
5757 [ NotifyPropertyChangedFor ( nameof ( DynamicWatermark ) ) ]
58+ [ NotifyPropertyChangedFor ( nameof ( ImageUploaders ) ) ]
59+ [ NotifyPropertyChangedFor ( nameof ( FileUploaders ) ) ]
60+ [ NotifyPropertyChangedFor ( nameof ( TextUploaders ) ) ]
61+ [ NotifyPropertyChangedFor ( nameof ( ShortenerUploaders ) ) ]
62+ [ NotifyPropertyChangedFor ( nameof ( SharingUploaders ) ) ]
5863 [ NotifyPropertyChangedFor ( nameof ( IsEmpty ) ) ]
5964 private CustomUploaderItem ? selectedUploader ;
6065
@@ -148,13 +153,11 @@ private async Task OpenCatalog()
148153
149154 if ( validJson . Count > 0 )
150155 {
151- TaskHelpers . ImportCustomUploaderJson ( validJson ) ;
156+ await Task . Run ( ( ) => TaskHelpers . ImportCustomUploaderJson ( validJson ) ) ;
152157 }
153158
154159 IsLoading = false ;
155160 TaskHelpers . PlayNotificationSoundAsync ( NotificationSound . ActionCompleted ) ;
156-
157- SelectedUploader = Uploaders . LastOrDefault ( ) ;
158161 }
159162 }
160163
@@ -194,6 +197,8 @@ private async Task PropagateData(CancellationToken cts = default)
194197 IsLoading = true ;
195198 DebugHelper . WriteLine ( "Propagating custom uploader data..." ) ;
196199 var UploadersConfig = App . SnapX . GetUploadersConfig ( ) ;
200+ var oldIndex = Uploaders . IndexOf ( SelectedUploader ! ) ;
201+ var oldCount = Uploaders . Count ;
197202 using ( await _collectionLock . AcquireAsync ( cts ) )
198203 {
199204 // There is no telling what happens if interrupted while modifying the collection
@@ -231,6 +236,23 @@ private async Task PropagateData(CancellationToken cts = default)
231236 SelectedSharingUploader = GetUploaderByIndex (
232237 UploadersConfig . CustomURLSharingServiceSelected
233238 ) ;
239+ if ( Uploaders . Count > oldCount )
240+ {
241+ // Likely an import occurred
242+ SelectedUploader = Uploaders . LastOrDefault ( ) ;
243+ DebugHelper . WriteLine ( $ "[Propagate] Collection grew. Selected last item: '{ SelectedUploader ? . Name } '") ;
244+ }
245+ else if ( oldIndex >= 0 && oldIndex < Uploaders . Count )
246+ {
247+ // Routine refresh, keep the user on the same row
248+ SelectedUploader = Uploaders [ oldIndex ] ;
249+ DebugHelper . WriteLine ( $ "[Propagate] Restored selection to index { oldIndex } : '{ SelectedUploader ? . Name } '") ;
250+ }
251+ else
252+ {
253+ SelectedUploader = Uploaders . LastOrDefault ( ) ;
254+ DebugHelper . WriteLine ( "[Propagate] Index invalid or item removed. Defaulting to LastOrDefault." ) ;
255+ }
234256 DebugHelper . WriteLine ( $ "Propagated { Uploaders . Count } custom uploaders.") ;
235257 }
236258 }
@@ -525,10 +547,9 @@ is IClassicDesktopStyleApplicationLifetime desktop
525547 }
526548
527549 IsLoading = true ;
528- TaskHelpers . ImportCustomUploader ( files . Select ( f => f . Path . LocalPath ) ) ;
550+ await Task . Run ( ( ) => TaskHelpers . ImportCustomUploader ( files . Select ( f => f . Path . LocalPath ) ) ) ;
529551 IsLoading = false ;
530552 TaskHelpers . PlayNotificationSoundAsync ( NotificationSound . ActionCompleted ) ;
531- SelectedUploader = Uploaders . LastOrDefault ( ) ;
532553 }
533554 catch ( Exception ex )
534555 {
0 commit comments