Skip to content

Commit cda587f

Browse files
Show toast when QL unavailable
1 parent 45a42a5 commit cda587f

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

Flow.Launcher/Helper/QuickLookHelper.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Security.Principal;
77
using System.Threading.Tasks;
88
using Flow.Launcher.Infrastructure.Logger;
9+
using Flow.Launcher.Core.Resource;
910

1011
namespace Flow.Launcher.Helper
1112
{
@@ -17,42 +18,47 @@ internal static class QuickLookHelper
1718
private static readonly string pipeMessageToggle = "QuickLook.App.PipeMessages.Toggle";
1819
private static readonly string pipeMessageClose = "QuickLook.App.PipeMessages.Close";
1920
private static readonly string pipeMessageInvoke = "QuickLook.App.PipeMessages.Invoke";
20-
21+
2122
/// <summary>
2223
/// Toggle QuickLook
2324
/// </summary>
2425
/// <param name="path">File path to preview</param>
2526
/// <param name="switchPreview">Is swtiching file</param>
2627
/// <returns></returns>
2728
public static async Task<bool> ToggleQuickLookAsync(string path, bool switchPreview = false)
28-
{
29-
//bool isQuickLookAvailable = await DetectQuickLookAvailabilityAsync();
30-
31-
//if (!isQuickLookAvailable)
32-
//{
33-
// if (!switchPreview)
34-
// {
35-
// Log.Warn($"{nameof(QuickLookHelper)}", "QuickLook not detected");
36-
// }
37-
// return;
38-
//}
39-
29+
{
4030
if (string.IsNullOrEmpty(path))
4131
return false;
4232

43-
return await SendQuickLookPipeMsgAsync(switchPreview ? pipeMessageSwitch : pipeMessageToggle, path);
33+
bool success = await SendQuickLookPipeMsgAsync(switchPreview ? pipeMessageSwitch : pipeMessageToggle, path);
34+
if (!success)
35+
{
36+
ShowQuickLookUnavailableToast();
37+
}
38+
return success;
4439
}
4540

4641
public static async Task<bool> CloseQuickLookAsync()
4742
{
48-
return await SendQuickLookPipeMsgAsync(pipeMessageClose);
43+
bool success = await SendQuickLookPipeMsgAsync(pipeMessageClose);
44+
if (!success)
45+
{
46+
ShowQuickLookUnavailableToast();
47+
}
48+
return success;
4949
}
5050

5151
public static async Task<bool> OpenQuickLookAsync(string path)
5252
{
5353
if (string.IsNullOrEmpty(path))
5454
return false;
55-
return await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
55+
56+
bool success = await SendQuickLookPipeMsgAsync(pipeMessageInvoke, path);
57+
if (!success)
58+
{
59+
ShowQuickLookUnavailableToast();
60+
}
61+
return success;
5662
}
5763

5864
private static async Task<bool> SendQuickLookPipeMsgAsync(string message, string arg = "")
@@ -80,7 +86,7 @@ private static async Task<bool> SendQuickLookPipeMsgAsync(string message, string
8086
return true;
8187
}
8288

83-
private static async Task<bool> DetectQuickLookAvailabilityAsync()
89+
public static async Task<bool> DetectQuickLookAvailabilityAsync()
8490
{
8591
static async Task<int> QuickLookServerAvailable()
8692
{
@@ -115,5 +121,11 @@ static async Task<int> QuickLookServerAvailable()
115121
return false;
116122
}
117123
}
124+
125+
private static void ShowQuickLookUnavailableToast()
126+
{
127+
Notification.Show(InternationalizationManager.Instance.GetTranslation("QuickLookFail"),
128+
InternationalizationManager.Instance.GetTranslation("QuickLookFailTips"));
129+
}
118130
}
119131
}

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@
309309

310310
<!-- General Notice -->
311311
<system:String x:Key="pleaseWait">Please wait...</system:String>
312+
<system:String x:Key="QuickLookFail">Failed to launch QuickLook</system:String>
313+
<system:String x:Key="QuickLookFailTips">Please check if QuickLook is running.</system:String>
312314

313315
<!-- Update -->
314316
<system:String x:Key="update_flowlauncher_update_check">Checking for new update</system:String>

0 commit comments

Comments
 (0)