Skip to content

Commit 7033bce

Browse files
Add minimum gap time between fail toasts
1 parent c705b01 commit 7033bce

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Flow.Launcher/Helper/QuickLookHelper.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ namespace Flow.Launcher.Helper
1313
internal static class QuickLookHelper
1414
{
1515
private const int TIMEOUT = 500;
16+
private static DateTime lastNotificationTime = DateTime.MinValue;
17+
1618
private static readonly string pipeName = $"QuickLook.App.Pipe.{WindowsIdentity.GetCurrent().User?.Value}";
1719
private static readonly string pipeMessageSwitch = "QuickLook.App.PipeMessages.Switch";
1820
private static readonly string pipeMessageToggle = "QuickLook.App.PipeMessages.Toggle";
1921
private static readonly string pipeMessageClose = "QuickLook.App.PipeMessages.Close";
2022
private static readonly string pipeMessageInvoke = "QuickLook.App.PipeMessages.Invoke";
21-
23+
24+
2225
/// <summary>
2326
/// Toggle QuickLook
2427
/// </summary>
@@ -64,14 +67,15 @@ public static async Task<bool> OpenQuickLookAsync(string path)
6467
/// Switch QuickLook to preview another file if it's on
6568
/// </summary>
6669
/// <param name="path">File path to preview</param>
70+
/// <param name="sendFailToast">Send notification if fail</param>
6771
/// <returns></returns>
68-
public static async Task<bool> SwitchQuickLookAsync(string path)
72+
public static async Task<bool> SwitchQuickLookAsync(string path, bool sendFailToast = false)
6973
{
7074
if (string.IsNullOrEmpty(path))
7175
return false;
7276

7377
bool success = await SendQuickLookPipeMsgAsync(pipeMessageSwitch, path);
74-
if (!success)
78+
if (sendFailToast && !success)
7579
{
7680
ShowQuickLookUnavailableToast();
7781
}
@@ -141,8 +145,12 @@ static async Task<int> QuickLookServerAvailable()
141145

142146
private static void ShowQuickLookUnavailableToast()
143147
{
144-
Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"),
148+
if (lastNotificationTime.AddSeconds(10) < DateTime.Now)
149+
{
150+
Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"),
145151
InternationalizationManager.Instance.GetTranslation("QuickLookFailTips"));
152+
lastNotificationTime = DateTime.Now;
153+
}
146154
}
147155
}
148156
}

0 commit comments

Comments
 (0)