Skip to content

Commit 2bb398d

Browse files
Add sendFailToast arg
1 parent 7033bce commit 2bb398d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Flow.Launcher/Helper/QuickLookHelper.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,38 @@ internal static class QuickLookHelper
2626
/// Toggle QuickLook
2727
/// </summary>
2828
/// <param name="path">File path to preview</param>
29+
/// <param name="sendFailToast">Send toast when fails.</param>
2930
/// <returns></returns>
30-
public static async Task<bool> ToggleQuickLookAsync(string path)
31+
public static async Task<bool> ToggleQuickLookAsync(string path, bool sendFailToast = true)
3132
{
3233
if (string.IsNullOrEmpty(path))
3334
return false;
3435

3536
bool success = await SendQuickLookPipeMsgAsync(pipeMessageToggle, path);
36-
if (!success)
37+
if (sendFailToast && !success)
3738
{
3839
ShowQuickLookUnavailableToast();
3940
}
4041
return success;
4142
}
4243

43-
public static async Task<bool> CloseQuickLookAsync()
44+
public static async Task<bool> CloseQuickLookAsync(bool sendFailToast = true)
4445
{
4546
bool success = await SendQuickLookPipeMsgAsync(pipeMessageClose);
46-
if (!success)
47+
if (sendFailToast && !success)
4748
{
4849
ShowQuickLookUnavailableToast();
4950
}
5051
return success;
5152
}
5253

53-
public static async Task<bool> OpenQuickLookAsync(string path)
54+
public static async Task<bool> OpenQuickLookAsync(string path, bool sendFailToast = true)
5455
{
5556
if (string.IsNullOrEmpty(path))
5657
return false;
5758

5859
bool success = await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
59-
if (!success)
60+
if (sendFailToast && !success)
6061
{
6162
ShowQuickLookUnavailableToast();
6263
}
@@ -69,7 +70,7 @@ public static async Task<bool> OpenQuickLookAsync(string path)
6970
/// <param name="path">File path to preview</param>
7071
/// <param name="sendFailToast">Send notification if fail</param>
7172
/// <returns></returns>
72-
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = false)
73+
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = true)
7374
{
7475
if (string.IsNullOrEmpty(path))
7576
return false;

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,29 +612,29 @@ private async Task ToggleExternalPreviewAsync(string path)
612612
}
613613
}
614614

615-
private async Task OpenExternalPreviewAsync(string path)
615+
private async Task OpenExternalPreviewAsync(string path, bool sendFailToast = true)
616616
{
617-
bool success = await QuickLookHelper.OpenQuickLookAsync(path).ConfigureAwait(false);
617+
bool success = await QuickLookHelper.OpenQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
618618
if (success)
619619
{
620-
ExternalPreviewOpen = true;
620+
ExternalPreviewOpen = false;
621621
}
622622
}
623623

624-
private async Task CloseExternalPreviewAsync()
624+
private async Task CloseExternalPreviewAsync(bool sendFailToast = true)
625625
{
626-
bool success = await QuickLookHelper.CloseQuickLookAsync().ConfigureAwait(false);
626+
bool success = await QuickLookHelper.CloseQuickLookAsync(sendFailToast).ConfigureAwait(false);
627627
if (success)
628628
{
629629
ExternalPreviewOpen = false;
630630
}
631631
}
632-
633-
private async Task SwitchExternalPreviewAsync(string path)
632+
633+
private async Task SwitchExternalPreviewAsync(string path, bool sendFailToast = true)
634634
{
635635
// Switches preview content
636636
// When external is off, do nothing
637-
_ = QuickLookHelper.SwitchQuickLookAsync(path).ConfigureAwait(false);
637+
_ = QuickLookHelper.SwitchQuickLookAsync(path, sendFailToast).ConfigureAwait(false);
638638
}
639639

640640
private void ShowInternalPreview()
@@ -672,7 +672,7 @@ private void UpdatePreview()
672672
{
673673
if (CanExternalPreviewSelectedResult(out var path))
674674
{
675-
_ = SwitchExternalPreviewAsync(path);
675+
_ = SwitchExternalPreviewAsync(path, false);
676676
}
677677
else
678678
{
@@ -1090,7 +1090,8 @@ public async void Hide()
10901090
// Trick for no delay
10911091
MainWindowOpacity = 0;
10921092

1093-
_ = CloseExternalPreviewAsync();
1093+
if (Settings.UseExternalPreview)
1094+
_ = CloseExternalPreviewAsync(false);
10941095

10951096
if (!SelectedIsFromQueryResults())
10961097
{

0 commit comments

Comments
 (0)