File tree Expand file tree Collapse file tree 4 files changed +25
-8
lines changed
Flow.Launcher.Core/Plugin Expand file tree Collapse file tree 4 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -14,5 +14,7 @@ public ExecutablePluginV2(string filename)
14
14
{
15
15
StartInfo = new ProcessStartInfo { FileName = filename } ;
16
16
}
17
+
18
+ protected override MessageHandlerType MessageHandler { get ; } = MessageHandlerType . NewLineDelimited ;
17
19
}
18
20
}
Original file line number Diff line number Diff line change @@ -86,12 +86,26 @@ async Task ReadErrorAsync()
86
86
87
87
public event ResultUpdatedEventHandler ResultsUpdated ;
88
88
89
+ protected enum MessageHandlerType
90
+ {
91
+ HeaderDelimited ,
92
+ LengthHeaderDelimited ,
93
+ NewLineDelimited
94
+ }
95
+
96
+ protected abstract MessageHandlerType MessageHandler { get ; }
97
+
89
98
90
99
private void SetupJsonRPC ( )
91
100
{
92
101
var formatter = new SystemTextJsonFormatter { JsonSerializerOptions = RequestSerializeOption } ;
93
- var handler = new NewLineDelimitedMessageHandler ( ClientPipe ,
94
- formatter ) ;
102
+ IJsonRpcMessageHandler handler = MessageHandler switch
103
+ {
104
+ MessageHandlerType . HeaderDelimited => new HeaderDelimitedMessageHandler ( ClientPipe , formatter ) ,
105
+ MessageHandlerType . LengthHeaderDelimited => new LengthHeaderMessageHandler ( ClientPipe , formatter ) ,
106
+ MessageHandlerType . NewLineDelimited => new NewLineDelimitedMessageHandler ( ClientPipe , formatter ) ,
107
+ _ => throw new ArgumentOutOfRangeException ( )
108
+ } ;
95
109
96
110
RPC = new JsonRpc ( handler , new JsonRPCPublicAPI ( Context . API ) ) ;
97
111
Original file line number Diff line number Diff line change @@ -24,5 +24,7 @@ public override async Task InitAsync(PluginInitContext context)
24
24
StartInfo . ArgumentList . Add ( context . CurrentPluginMetadata . ExecuteFilePath ) ;
25
25
await base . InitAsync ( context ) ;
26
26
}
27
+
28
+ protected override MessageHandlerType MessageHandler { get ; } = MessageHandlerType . HeaderDelimited ;
27
29
}
28
30
}
Original file line number Diff line number Diff line change @@ -19,25 +19,24 @@ namespace Flow.Launcher.Core.Plugin
19
19
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
20
20
{
21
21
protected override ProcessStartInfo StartInfo { get ; set ; }
22
-
22
+
23
23
public PythonPluginV2 ( string filename )
24
24
{
25
- StartInfo = new ProcessStartInfo
26
- {
27
- FileName = filename ,
28
- } ;
25
+ StartInfo = new ProcessStartInfo { FileName = filename , } ;
29
26
30
27
var path = Path . Combine ( Constant . ProgramDirectory , JsonRpc ) ;
31
28
StartInfo . EnvironmentVariables [ "PYTHONPATH" ] = path ;
32
29
33
30
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
34
31
StartInfo . ArgumentList . Add ( "-B" ) ;
35
32
}
36
-
33
+
37
34
public override async Task InitAsync ( PluginInitContext context )
38
35
{
39
36
StartInfo . ArgumentList . Add ( context . CurrentPluginMetadata . ExecuteFilePath ) ;
40
37
await base . InitAsync ( context ) ;
41
38
}
39
+
40
+ protected override MessageHandlerType MessageHandler { get ; } = MessageHandlerType . NewLineDelimited ;
42
41
}
43
42
}
You can’t perform that action at this time.
0 commit comments