@@ -644,7 +644,14 @@ public async void RecognizeText()
644
644
return ;
645
645
}
646
646
647
- var service = TypeResolver . Current . Resolve < ITextRecognitionService > ( _window . ViewModel . SessionId ) ;
647
+ var viewModel = _window . ViewModel ;
648
+ if ( viewModel == null )
649
+ {
650
+ return ;
651
+ }
652
+
653
+ var fileId = _itemId ;
654
+ var service = TypeResolver . Current . Resolve < ITextRecognitionService > ( viewModel . SessionId ) ;
648
655
649
656
var status = await service . EnsureReadyAsync ( ) ;
650
657
if ( status is TextRecognitionStatusUnavailable unavailable )
@@ -654,11 +661,11 @@ public async void RecognizeText()
654
661
WatchDog . TrackEvent ( "TextRecognizer" , new Properties { { "Status" , "Unavailable" } } ) ;
655
662
return ;
656
663
}
657
- else if ( status is TextRecognitionStatusDownloading downloading )
664
+ else if ( status is TextRecognitionStatusDownloading downloading && fileId == _fileId && IsLoaded )
658
665
{
659
666
WatchDog . TrackEvent ( "TextRecognizer" , new Properties { { "Status" , "Downloading" } } ) ;
660
667
661
- var confirm = await _window . ViewModel . ShowPopupAsync ( new TextRecognitionDownloadPopup ( _window . ViewModel . ClientService , _window . ViewModel . Aggregator , downloading . Document ) , requestedTheme : ElementTheme . Dark ) ;
668
+ var confirm = await viewModel . ShowPopupAsync ( new TextRecognitionDownloadPopup ( viewModel . ClientService , viewModel . Aggregator , downloading . Document ) , requestedTheme : ElementTheme . Dark ) ;
662
669
if ( confirm != ContentDialogResult . Primary )
663
670
{
664
671
return ;
@@ -671,7 +678,7 @@ public async void RecognizeText()
671
678
WatchDog . TrackEvent ( "TextRecognizer" , new Properties { { "Status" , "Available" } } ) ;
672
679
}
673
680
674
- if ( status is not TextRecognitionStatusAvailable available )
681
+ if ( status is not TextRecognitionStatusAvailable available || fileId != _itemId || ! IsLoaded )
675
682
{
676
683
// TODO: Error: not available
677
684
return ;
@@ -680,9 +687,7 @@ public async void RecognizeText()
680
687
IsTextSelectionEnabled = true ;
681
688
Selection . ShowSkeleton ( ) ;
682
689
683
- var fileId = _itemId ;
684
-
685
- var bitmap = await GetSoftwareBitmapAsync ( _item . File ) ;
690
+ var bitmap = await GetSoftwareBitmapAsync ( _item ? . File ) ;
686
691
if ( bitmap == null )
687
692
{
688
693
// TODO: Error: text recognition is not available
@@ -721,6 +726,11 @@ public async void RecognizeText()
721
726
722
727
public async Task < SoftwareBitmap > GetSoftwareBitmapAsync ( File file )
723
728
{
729
+ if ( _window ? . ViewModel == null )
730
+ {
731
+ return null ;
732
+ }
733
+
724
734
var storage = await _window . ViewModel . ClientService . GetFileAsync ( file ) ;
725
735
if ( storage == null )
726
736
{
0 commit comments