1- using Flow . Launcher . Core . Resource ;
2- using System ;
1+ using System ;
32using System . Collections . Generic ;
43using System . Diagnostics ;
54using System . IO ;
65using System . Text ;
76using System . Text . Json ;
87using System . Threading ;
98using System . Threading . Tasks ;
10- using Flow . Launcher . Infrastructure . Logger ;
9+ using Flow . Launcher . Core . Resource ;
1110using Flow . Launcher . Plugin ;
1211using Microsoft . IO ;
13- using System . Windows ;
1412
1513namespace Flow . Launcher . Core . Plugin
1614{
@@ -20,7 +18,9 @@ namespace Flow.Launcher.Core.Plugin
2018 /// </summary>
2119 internal abstract class JsonRPCPlugin : JsonRPCPluginBase
2220 {
23- public const string JsonRPC = "JsonRPC" ;
21+ public new const string JsonRPC = "JsonRPC" ;
22+
23+ private static readonly string ClassName = nameof ( JsonRPCPlugin ) ;
2424
2525 protected abstract Task < Stream > RequestAsync ( JsonRPCRequestModel rpcRequest , CancellationToken token = default ) ;
2626 protected abstract string Request ( JsonRPCRequestModel rpcRequest , CancellationToken token = default ) ;
@@ -29,9 +29,6 @@ internal abstract class JsonRPCPlugin : JsonRPCPluginBase
2929
3030 private int RequestId { get ; set ; }
3131
32- private string SettingConfigurationPath => Path . Combine ( Context . CurrentPluginMetadata . PluginDirectory , "SettingsTemplate.yaml" ) ;
33- private string SettingPath => Path . Combine ( Context . CurrentPluginMetadata . PluginSettingsDirectoryPath , "Settings.json" ) ;
34-
3532 public override List < Result > LoadContextMenus ( Result selectedResult )
3633 {
3734 var request = new JsonRPCRequestModel ( RequestId ++ ,
@@ -57,13 +54,6 @@ public override List<Result> LoadContextMenus(Result selectedResult)
5754 }
5855 } ;
5956
60- private static readonly JsonSerializerOptions settingSerializeOption = new ( )
61- {
62- WriteIndented = true
63- } ;
64-
65- private readonly Dictionary < string , FrameworkElement > _settingControls = new ( ) ;
66-
6757 private async Task < List < Result > > DeserializedResultAsync ( Stream output )
6858 {
6959 await using ( output )
@@ -122,7 +112,6 @@ protected override async Task<bool> ExecuteResultAsync(JsonRPCResult result)
122112 return ! result . JsonRPCAction . DontHideAfterAction ;
123113 }
124114
125-
126115 /// <summary>
127116 /// Execute external program and return the output
128117 /// </summary>
@@ -160,20 +149,20 @@ protected string Execute(ProcessStartInfo startInfo)
160149 var error = standardError . ReadToEnd ( ) ;
161150 if ( ! string . IsNullOrEmpty ( error ) )
162151 {
163- Log . Error ( $ "|JsonRPCPlugin.Execute| { error } " ) ;
152+ Context . API . LogError ( ClassName , error ) ;
164153 return string . Empty ;
165154 }
166155
167- Log . Error ( "|JsonRPCPlugin.Execute| Empty standard output and standard error.") ;
156+ Context . API . LogError ( ClassName , " Empty standard output and standard error.") ;
168157 return string . Empty ;
169158 }
170159
171160 return result ;
172161 }
173162 catch ( Exception e )
174163 {
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 } >",
177166 e ) ;
178167 return string . Empty ;
179168 }
@@ -184,7 +173,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
184173 using var process = Process . Start ( startInfo ) ;
185174 if ( process == null )
186175 {
187- Log . Error ( "|JsonRPCPlugin.ExecuteAsync| Can't start new process") ;
176+ Context . API . LogError ( ClassName , " Can't start new process") ;
188177 return Stream . Null ;
189178 }
190179
@@ -204,7 +193,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
204193 }
205194 catch ( Exception e )
206195 {
207- Log . Exception ( "|JsonRPCPlugin.ExecuteAsync| Exception when kill process", e ) ;
196+ Context . API . LogException ( ClassName , " Exception when kill process", e ) ;
208197 }
209198 } ) ;
210199
@@ -225,7 +214,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
225214 {
226215 case ( 0 , 0 ) :
227216 const string errorMessage = "Empty JSON-RPC Response." ;
228- Log . Warn ( $ "| { nameof ( JsonRPCPlugin ) } . { nameof ( ExecuteAsync ) } | { errorMessage } " ) ;
217+ Context . API . LogWarn ( ClassName , errorMessage ) ;
229218 break ;
230219 case ( _, not 0 ) :
231220 throw new InvalidDataException ( Encoding . UTF8 . GetString ( errorBuffer . ToArray ( ) ) ) ; // The process has exited with an error message
0 commit comments