Skip to content

Commit 2882d18

Browse files
committed
use HeaderDeliminatedHandler for NodePlugin while NewLineDeliminated for everything else
1 parent 692eb13 commit 2882d18

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public ExecutablePluginV2(string filename)
1414
{
1515
StartInfo = new ProcessStartInfo { FileName = filename };
1616
}
17+
18+
protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited;
1719
}
1820
}

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,26 @@ async Task ReadErrorAsync()
8686

8787
public event ResultUpdatedEventHandler ResultsUpdated;
8888

89+
protected enum MessageHandlerType
90+
{
91+
HeaderDelimited,
92+
LengthHeaderDelimited,
93+
NewLineDelimited
94+
}
95+
96+
protected abstract MessageHandlerType MessageHandler { get; }
97+
8998

9099
private void SetupJsonRPC()
91100
{
92101
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+
};
95109

96110
RPC = new JsonRpc(handler, new JsonRPCPublicAPI(Context.API));
97111

Flow.Launcher.Core/Plugin/NodePluginV2.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ public override async Task InitAsync(PluginInitContext context)
2424
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
2525
await base.InitAsync(context);
2626
}
27+
28+
protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.HeaderDelimited;
2729
}
2830
}

Flow.Launcher.Core/Plugin/PythonPluginV2.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@ namespace Flow.Launcher.Core.Plugin
1919
internal sealed class PythonPluginV2 : ProcessStreamPluginV2
2020
{
2121
protected override ProcessStartInfo StartInfo { get; set; }
22-
22+
2323
public PythonPluginV2(string filename)
2424
{
25-
StartInfo = new ProcessStartInfo
26-
{
27-
FileName = filename,
28-
};
25+
StartInfo = new ProcessStartInfo { FileName = filename, };
2926

3027
var path = Path.Combine(Constant.ProgramDirectory, JsonRpc);
3128
StartInfo.EnvironmentVariables["PYTHONPATH"] = path;
3229

3330
//Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable
3431
StartInfo.ArgumentList.Add("-B");
3532
}
36-
33+
3734
public override async Task InitAsync(PluginInitContext context)
3835
{
3936
StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath);
4037
await base.InitAsync(context);
4138
}
39+
40+
protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited;
4241
}
4342
}

0 commit comments

Comments
 (0)