From 7033bce433fd6eb41e5a2c6e1c3327bf496e43ae Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Mon, 22 May 2023 20:36:34 +0800 Subject: [PATCH] Add minimum gap time between fail toasts --- Flow.Launcher/Helper/QuickLookHelper.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/Helper/QuickLookHelper.cs b/Flow.Launcher/Helper/QuickLookHelper.cs index 59c94ae2f..f5023cfc7 100644 --- a/Flow.Launcher/Helper/QuickLookHelper.cs +++ b/Flow.Launcher/Helper/QuickLookHelper.cs @@ -13,12 +13,15 @@ namespace Flow.Launcher.Helper internal static class QuickLookHelper { private const int TIMEOUT = 500; + private static DateTime lastNotificationTime = DateTime.MinValue; + private static readonly string pipeName = $"QuickLook.App.Pipe.{WindowsIdentity.GetCurrent().User?.Value}"; private static readonly string pipeMessageSwitch = "QuickLook.App.PipeMessages.Switch"; private static readonly string pipeMessageToggle = "QuickLook.App.PipeMessages.Toggle"; private static readonly string pipeMessageClose = "QuickLook.App.PipeMessages.Close"; private static readonly string pipeMessageInvoke = "QuickLook.App.PipeMessages.Invoke"; - + + /// /// Toggle QuickLook /// @@ -64,14 +67,15 @@ namespace Flow.Launcher.Helper /// Switch QuickLook to preview another file if it's on /// /// File path to preview + /// Send notification if fail /// - public static async Task SwitchQuickLookAsync(string path) + public static async Task SwitchQuickLookAsync(string path, bool sendFailToast = false) { if (string.IsNullOrEmpty(path)) return false; bool success = await SendQuickLookPipeMsgAsync(pipeMessageSwitch, path); - if (!success) + if (sendFailToast && !success) { ShowQuickLookUnavailableToast(); } @@ -141,8 +145,12 @@ namespace Flow.Launcher.Helper private static void ShowQuickLookUnavailableToast() { - Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"), + if (lastNotificationTime.AddSeconds(10) < DateTime.Now) + { + Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"), InternationalizationManager.Instance.GetTranslation("QuickLookFailTips")); + lastNotificationTime = DateTime.Now; + } } } }