From cda587fb585b4fe89c5db9e338c0bb00a6bcfd83 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 23 Apr 2023 20:52:10 +0800
Subject: [PATCH] Show toast when QL unavailable
---
Flow.Launcher/Helper/QuickLookHelper.cs | 46 ++++++++++++++++---------
Flow.Launcher/Languages/en.xaml | 2 ++
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/Flow.Launcher/Helper/QuickLookHelper.cs b/Flow.Launcher/Helper/QuickLookHelper.cs
index 136f86cdb..0d8251f1f 100644
--- a/Flow.Launcher/Helper/QuickLookHelper.cs
+++ b/Flow.Launcher/Helper/QuickLookHelper.cs
@@ -6,6 +6,7 @@ using System.IO;
using System.Security.Principal;
using System.Threading.Tasks;
using Flow.Launcher.Infrastructure.Logger;
+using Flow.Launcher.Core.Resource;
namespace Flow.Launcher.Helper
{
@@ -17,7 +18,7 @@ namespace Flow.Launcher.Helper
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
///
@@ -25,34 +26,39 @@ namespace Flow.Launcher.Helper
/// Is swtiching file
///
public static async Task ToggleQuickLookAsync(string path, bool switchPreview = false)
- {
- //bool isQuickLookAvailable = await DetectQuickLookAvailabilityAsync();
-
- //if (!isQuickLookAvailable)
- //{
- // if (!switchPreview)
- // {
- // Log.Warn($"{nameof(QuickLookHelper)}", "QuickLook not detected");
- // }
- // return;
- //}
-
+ {
if (string.IsNullOrEmpty(path))
return false;
- return await SendQuickLookPipeMsgAsync(switchPreview ? pipeMessageSwitch : pipeMessageToggle, path);
+ bool success = await SendQuickLookPipeMsgAsync(switchPreview ? pipeMessageSwitch : pipeMessageToggle, path);
+ if (!success)
+ {
+ ShowQuickLookUnavailableToast();
+ }
+ return success;
}
public static async Task CloseQuickLookAsync()
{
- return await SendQuickLookPipeMsgAsync(pipeMessageClose);
+ bool success = await SendQuickLookPipeMsgAsync(pipeMessageClose);
+ if (!success)
+ {
+ ShowQuickLookUnavailableToast();
+ }
+ return success;
}
public static async Task OpenQuickLookAsync(string path)
{
if (string.IsNullOrEmpty(path))
return false;
- return await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
+
+ bool success = await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
+ if (!success)
+ {
+ ShowQuickLookUnavailableToast();
+ }
+ return success;
}
private static async Task SendQuickLookPipeMsgAsync(string message, string arg = "")
@@ -80,7 +86,7 @@ namespace Flow.Launcher.Helper
return true;
}
- private static async Task DetectQuickLookAvailabilityAsync()
+ public static async Task DetectQuickLookAvailabilityAsync()
{
static async Task QuickLookServerAvailable()
{
@@ -115,5 +121,11 @@ namespace Flow.Launcher.Helper
return false;
}
}
+
+ private static void ShowQuickLookUnavailableToast()
+ {
+ Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"),
+ InternationalizationManager.Instance.GetTranslation("QuickLookFailTips"));
+ }
}
}
diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml
index e3433b98f..2f2c3c8bf 100644
--- a/Flow.Launcher/Languages/en.xaml
+++ b/Flow.Launcher/Languages/en.xaml
@@ -309,6 +309,8 @@
Please wait...
+ Failed to launch QuickLook
+ Please check if QuickLook is running.
Checking for new update