Skip to content

Commit d266e9e

Browse files
Simplify QuickLook logic
- Only try to use QuickLook when built-in preview is hidden
1 parent 64afeed commit d266e9e

File tree

1 file changed

+39
-50
lines changed

1 file changed

+39
-50
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -570,25 +570,23 @@ public string PreviewHotkey
570570

571571
#region Preview
572572

573+
// Not accurate
574+
public bool ExternalPreviewOpen { get; set; } = false;
575+
573576
[RelayCommand]
574577
private void TogglePreview()
575578
{
576-
if (Settings.UseExternalPreview && CanExternalPreviewSelectedResult(out var path))
579+
if (PreviewVisible)
577580
{
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);
587586
}
588587
else
589588
{
590-
// Fallback
591-
ToggleInternalPreview();
589+
ShowInternalPreview();
592590
}
593591
}
594592

@@ -604,22 +602,34 @@ private void ToggleInternalPreview()
604602
}
605603
}
606604

607-
private void ToggleExternalPreview(string path)
605+
private async Task ToggleExternalPreviewAsync(string path)
608606
{
609-
_ = QuickLookHelper.ToggleQuickLookAsync(path).ConfigureAwait(false);
607+
bool success = await QuickLookHelper.ToggleQuickLookAsync(path).ConfigureAwait(false);
608+
if (success)
609+
{
610+
ExternalPreviewOpen = !ExternalPreviewOpen;
611+
}
610612
}
611613

612-
private void OpenExternalPreview(string path)
614+
private async Task OpenExternalPreviewAsync(string path)
613615
{
614-
_ = QuickLookHelper.OpenQuickLookAsync(path).ConfigureAwait(false);
616+
bool success = await QuickLookHelper.OpenQuickLookAsync(path).ConfigureAwait(false);
617+
if (success)
618+
{
619+
ExternalPreviewOpen = true;
620+
}
615621
}
616-
617-
private void CloseExternalPreview()
622+
623+
private async Task CloseExternalPreviewAsync()
618624
{
619-
_ = QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
625+
bool success = await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
626+
if (success)
627+
{
628+
ExternalPreviewOpen = false;
629+
}
620630
}
621-
622-
private void SwitchExternalPreview(string path)
631+
632+
private async Task SwitchExternalPreviewAsync(string path)
623633
{
624634
// Switches preview content
625635
// When external is off, do nothing
@@ -653,42 +663,21 @@ public void ResetPreview()
653663

654664
private void UpdatePreview()
655665
{
656-
if (Settings.UseExternalPreview)
666+
if (PreviewVisible)
667+
{
668+
Results.SelectedItem?.LoadPreviewImage();
669+
}
670+
else if (Settings.UseExternalPreview)
657671
{
658672
if (CanExternalPreviewSelectedResult(out var path))
659673
{
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);
674675
}
675676
else
676677
{
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();
686679
}
687680
}
688-
else if(PreviewVisible)
689-
{
690-
Results.SelectedItem?.LoadPreviewImage();
691-
}
692681
}
693682

694683
private bool CanExternalPreviewSelectedResult(out string path)
@@ -1100,7 +1089,7 @@ public async void Hide()
11001089
// Trick for no delay
11011090
MainWindowOpacity = 0;
11021091

1103-
CloseExternalPreview();
1092+
_ = CloseExternalPreviewAsync();
11041093

11051094
if (!SelectedIsFromQueryResults())
11061095
{

0 commit comments

Comments
 (0)