1
- using Flow . Launcher . Core . Resource ;
2
- using System ;
1
+ using System ;
3
2
using System . Collections . Generic ;
4
3
using System . Diagnostics ;
5
4
using System . IO ;
6
5
using System . Text ;
7
6
using System . Text . Json ;
8
7
using System . Threading ;
9
8
using System . Threading . Tasks ;
10
- using Flow . Launcher . Infrastructure . Logger ;
9
+ using Flow . Launcher . Core . Resource ;
11
10
using Flow . Launcher . Plugin ;
12
11
using Microsoft . IO ;
13
- using System . Windows ;
14
12
15
13
namespace Flow . Launcher . Core . Plugin
16
14
{
@@ -20,7 +18,9 @@ namespace Flow.Launcher.Core.Plugin
20
18
/// </summary>
21
19
internal abstract class JsonRPCPlugin : JsonRPCPluginBase
22
20
{
23
- public const string JsonRPC = "JsonRPC" ;
21
+ public new const string JsonRPC = "JsonRPC" ;
22
+
23
+ private static readonly string ClassName = nameof ( JsonRPCPlugin ) ;
24
24
25
25
protected abstract Task < Stream > RequestAsync ( JsonRPCRequestModel rpcRequest , CancellationToken token = default ) ;
26
26
protected abstract string Request ( JsonRPCRequestModel rpcRequest , CancellationToken token = default ) ;
@@ -29,9 +29,6 @@ internal abstract class JsonRPCPlugin : JsonRPCPluginBase
29
29
30
30
private int RequestId { get ; set ; }
31
31
32
- private string SettingConfigurationPath => Path . Combine ( Context . CurrentPluginMetadata . PluginDirectory , "SettingsTemplate.yaml" ) ;
33
- private string SettingPath => Path . Combine ( Context . CurrentPluginMetadata . PluginSettingsDirectoryPath , "Settings.json" ) ;
34
-
35
32
public override List < Result > LoadContextMenus ( Result selectedResult )
36
33
{
37
34
var request = new JsonRPCRequestModel ( RequestId ++ ,
@@ -57,13 +54,6 @@ public override List<Result> LoadContextMenus(Result selectedResult)
57
54
}
58
55
} ;
59
56
60
- private static readonly JsonSerializerOptions settingSerializeOption = new ( )
61
- {
62
- WriteIndented = true
63
- } ;
64
-
65
- private readonly Dictionary < string , FrameworkElement > _settingControls = new ( ) ;
66
-
67
57
private async Task < List < Result > > DeserializedResultAsync ( Stream output )
68
58
{
69
59
await using ( output )
@@ -122,7 +112,6 @@ protected override async Task<bool> ExecuteResultAsync(JsonRPCResult result)
122
112
return ! result . JsonRPCAction . DontHideAfterAction ;
123
113
}
124
114
125
-
126
115
/// <summary>
127
116
/// Execute external program and return the output
128
117
/// </summary>
@@ -160,20 +149,20 @@ protected string Execute(ProcessStartInfo startInfo)
160
149
var error = standardError . ReadToEnd ( ) ;
161
150
if ( ! string . IsNullOrEmpty ( error ) )
162
151
{
163
- Log . Error ( $ "|JsonRPCPlugin.Execute| { error } " ) ;
152
+ Context . API . LogError ( ClassName , error ) ;
164
153
return string . Empty ;
165
154
}
166
155
167
- Log . Error ( "|JsonRPCPlugin.Execute| Empty standard output and standard error.") ;
156
+ Context . API . LogError ( ClassName , " Empty standard output and standard error.") ;
168
157
return string . Empty ;
169
158
}
170
159
171
160
return result ;
172
161
}
173
162
catch ( Exception e )
174
163
{
175
- Log . Exception (
176
- $ "|JsonRPCPlugin.Execute| Exception for filename <{ startInfo . FileName } > with argument <{ startInfo . Arguments } >",
164
+ Context . API . LogException ( ClassName ,
165
+ $ "Exception for filename <{ startInfo . FileName } > with argument <{ startInfo . Arguments } >",
177
166
e ) ;
178
167
return string . Empty ;
179
168
}
@@ -184,7 +173,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
184
173
using var process = Process . Start ( startInfo ) ;
185
174
if ( process == null )
186
175
{
187
- Log . Error ( "|JsonRPCPlugin.ExecuteAsync| Can't start new process") ;
176
+ Context . API . LogError ( ClassName , " Can't start new process") ;
188
177
return Stream . Null ;
189
178
}
190
179
@@ -204,7 +193,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
204
193
}
205
194
catch ( Exception e )
206
195
{
207
- Log . Exception ( "|JsonRPCPlugin.ExecuteAsync| Exception when kill process", e ) ;
196
+ Context . API . LogException ( ClassName , " Exception when kill process", e ) ;
208
197
}
209
198
} ) ;
210
199
@@ -225,7 +214,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
225
214
{
226
215
case ( 0 , 0 ) :
227
216
const string errorMessage = "Empty JSON-RPC Response." ;
228
- Log . Warn ( $ "| { nameof ( JsonRPCPlugin ) } . { nameof ( ExecuteAsync ) } | { errorMessage } " ) ;
217
+ Context . API . LogWarn ( ClassName , errorMessage ) ;
229
218
break ;
230
219
case ( _, not 0 ) :
231
220
throw new InvalidDataException ( Encoding . UTF8 . GetString ( errorBuffer . ToArray ( ) ) ) ; // The process has exited with an error message
0 commit comments