@@ -570,25 +570,23 @@ public string PreviewHotkey
570
570
571
571
#region Preview
572
572
573
+ // Not accurate
574
+ public bool ExternalPreviewOpen { get ; set ; } = false ;
575
+
573
576
[ RelayCommand ]
574
577
private void TogglePreview ( )
575
578
{
576
- if ( Settings . UseExternalPreview && CanExternalPreviewSelectedResult ( out var path ) )
579
+ if ( PreviewVisible )
577
580
{
578
- if ( Settings . AlwaysPreview == true && PreviewVisible )
579
- {
580
- // Only hit this line at first preview toggle after toggle on Flow
581
- HideInternalPreview ( ) ; // When Always preview, toggle off rather than open external
582
- }
583
- else
584
- {
585
- ToggleExternalPreview ( path ) ;
586
- }
581
+ HideInternalPreview ( ) ;
582
+ }
583
+ else if ( Settings . UseExternalPreview && CanExternalPreviewSelectedResult ( out var path ) )
584
+ {
585
+ _ = ToggleExternalPreviewAsync ( path ) ;
587
586
}
588
587
else
589
588
{
590
- // Fallback
591
- ToggleInternalPreview ( ) ;
589
+ ShowInternalPreview ( ) ;
592
590
}
593
591
}
594
592
@@ -604,22 +602,34 @@ private void ToggleInternalPreview()
604
602
}
605
603
}
606
604
607
- private void ToggleExternalPreview ( string path )
605
+ private async Task ToggleExternalPreviewAsync ( string path )
608
606
{
609
- _ = QuickLookHelper . ToggleQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
607
+ bool success = await QuickLookHelper . ToggleQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
608
+ if ( success )
609
+ {
610
+ ExternalPreviewOpen = ! ExternalPreviewOpen ;
611
+ }
610
612
}
611
613
612
- private void OpenExternalPreview ( string path )
614
+ private async Task OpenExternalPreviewAsync ( string path )
613
615
{
614
- _ = QuickLookHelper . OpenQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
616
+ bool success = await QuickLookHelper . OpenQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
617
+ if ( success )
618
+ {
619
+ ExternalPreviewOpen = true ;
620
+ }
615
621
}
616
-
617
- private void CloseExternalPreview ( )
622
+
623
+ private async Task CloseExternalPreviewAsync ( )
618
624
{
619
- _ = QuickLookHelper . CloseQuickLookAsync ( ) . ConfigureAwait ( false ) ;
625
+ bool success = await QuickLookHelper . CloseQuickLookAsync ( ) . ConfigureAwait ( false ) ;
626
+ if ( success )
627
+ {
628
+ ExternalPreviewOpen = false ;
629
+ }
620
630
}
621
-
622
- private void SwitchExternalPreview ( string path )
631
+
632
+ private async Task SwitchExternalPreviewAsync ( string path )
623
633
{
624
634
// Switches preview content
625
635
// When external is off, do nothing
@@ -653,42 +663,21 @@ public void ResetPreview()
653
663
654
664
private void UpdatePreview ( )
655
665
{
656
- if ( Settings . UseExternalPreview )
666
+ if ( PreviewVisible )
667
+ {
668
+ Results . SelectedItem ? . LoadPreviewImage ( ) ;
669
+ }
670
+ else if ( Settings . UseExternalPreview )
657
671
{
658
672
if ( CanExternalPreviewSelectedResult ( out var path ) )
659
673
{
660
- // Should use external preview for selected result
661
- if ( PreviewVisible )
662
- {
663
- // Previewing
664
- // When internal is open and select a result that should use external preview
665
- // External must be off when PreviewVisible
666
- HideInternalPreview ( ) ;
667
- OpenExternalPreview ( path ) ;
668
- }
669
- else
670
- {
671
- // Internal is off, try to switch preview content
672
- SwitchExternalPreview ( path ) ;
673
- }
674
+ _ = SwitchExternalPreviewAsync ( path ) ;
674
675
}
675
676
else
676
677
{
677
- // Should use internal preview for selected result
678
- if ( PreviewVisible )
679
- {
680
- Results . SelectedItem ? . LoadPreviewImage ( ) ;
681
- }
682
- else
683
- {
684
- CloseExternalPreview ( ) ; // Forcibly close, ideally should only close when it's on
685
- }
678
+ _ = CloseExternalPreviewAsync ( ) ;
686
679
}
687
680
}
688
- else if ( PreviewVisible )
689
- {
690
- Results . SelectedItem ? . LoadPreviewImage ( ) ;
691
- }
692
681
}
693
682
694
683
private bool CanExternalPreviewSelectedResult ( out string path )
@@ -1100,7 +1089,7 @@ public async void Hide()
1100
1089
// Trick for no delay
1101
1090
MainWindowOpacity = 0 ;
1102
1091
1103
- CloseExternalPreview ( ) ;
1092
+ _ = CloseExternalPreviewAsync ( ) ;
1104
1093
1105
1094
if ( ! SelectedIsFromQueryResults ( ) )
1106
1095
{
0 commit comments