6
6
using System . Security . Principal ;
7
7
using System . Threading . Tasks ;
8
8
using Flow . Launcher . Infrastructure . Logger ;
9
+ using Flow . Launcher . Core . Resource ;
9
10
10
11
namespace Flow . Launcher . Helper
11
12
{
@@ -17,42 +18,47 @@ internal static class QuickLookHelper
17
18
private static readonly string pipeMessageToggle = "QuickLook.App.PipeMessages.Toggle" ;
18
19
private static readonly string pipeMessageClose = "QuickLook.App.PipeMessages.Close" ;
19
20
private static readonly string pipeMessageInvoke = "QuickLook.App.PipeMessages.Invoke" ;
20
-
21
+
21
22
/// <summary>
22
23
/// Toggle QuickLook
23
24
/// </summary>
24
25
/// <param name="path">File path to preview</param>
25
26
/// <param name="switchPreview">Is swtiching file</param>
26
27
/// <returns></returns>
27
28
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
+ {
40
30
if ( string . IsNullOrEmpty ( path ) )
41
31
return false ;
42
32
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 ;
44
39
}
45
40
46
41
public static async Task < bool > CloseQuickLookAsync ( )
47
42
{
48
- return await SendQuickLookPipeMsgAsync ( pipeMessageClose ) ;
43
+ bool success = await SendQuickLookPipeMsgAsync ( pipeMessageClose ) ;
44
+ if ( ! success )
45
+ {
46
+ ShowQuickLookUnavailableToast ( ) ;
47
+ }
48
+ return success ;
49
49
}
50
50
51
51
public static async Task < bool > OpenQuickLookAsync ( string path )
52
52
{
53
53
if ( string . IsNullOrEmpty ( path ) )
54
54
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 ;
56
62
}
57
63
58
64
private static async Task < bool > SendQuickLookPipeMsgAsync ( string message , string arg = "" )
@@ -80,7 +86,7 @@ private static async Task<bool> SendQuickLookPipeMsgAsync(string message, string
80
86
return true ;
81
87
}
82
88
83
- private static async Task < bool > DetectQuickLookAvailabilityAsync ( )
89
+ public static async Task < bool > DetectQuickLookAvailabilityAsync ( )
84
90
{
85
91
static async Task < int > QuickLookServerAvailable ( )
86
92
{
@@ -115,5 +121,11 @@ static async Task<int> QuickLookServerAvailable()
115
121
return false ;
116
122
}
117
123
}
124
+
125
+ private static void ShowQuickLookUnavailableToast ( )
126
+ {
127
+ Notification . Show ( InternationalizationManager . Instance . GetTranslation ( "QuickLookFail" ) ,
128
+ InternationalizationManager . Instance . GetTranslation ( "QuickLookFailTips" ) ) ;
129
+ }
118
130
}
119
131
}
0 commit comments