diff --git a/Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs b/Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs index 128b28638..852f57b9f 100644 --- a/Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs +++ b/Flow.Launcher.Core/Plugin/ExecutablePluginV2.cs @@ -14,5 +14,7 @@ namespace Flow.Launcher.Core.Plugin { StartInfo = new ProcessStartInfo { FileName = filename }; } + + protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited; } } diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs b/Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs index 1d2389b4f..1ad6edc2c 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs @@ -86,12 +86,26 @@ namespace Flow.Launcher.Core.Plugin public event ResultUpdatedEventHandler ResultsUpdated; + protected enum MessageHandlerType + { + HeaderDelimited, + LengthHeaderDelimited, + NewLineDelimited + } + + protected abstract MessageHandlerType MessageHandler { get; } + private void SetupJsonRPC() { var formatter = new SystemTextJsonFormatter { JsonSerializerOptions = RequestSerializeOption }; - var handler = new NewLineDelimitedMessageHandler(ClientPipe, - formatter); + IJsonRpcMessageHandler handler = MessageHandler switch + { + MessageHandlerType.HeaderDelimited => new HeaderDelimitedMessageHandler(ClientPipe, formatter), + MessageHandlerType.LengthHeaderDelimited => new LengthHeaderMessageHandler(ClientPipe, formatter), + MessageHandlerType.NewLineDelimited => new NewLineDelimitedMessageHandler(ClientPipe, formatter), + _ => throw new ArgumentOutOfRangeException() + }; RPC = new JsonRpc(handler, new JsonRPCPublicAPI(Context.API)); diff --git a/Flow.Launcher.Core/Plugin/NodePluginV2.cs b/Flow.Launcher.Core/Plugin/NodePluginV2.cs index d84a72864..c8cc37c57 100644 --- a/Flow.Launcher.Core/Plugin/NodePluginV2.cs +++ b/Flow.Launcher.Core/Plugin/NodePluginV2.cs @@ -24,5 +24,7 @@ namespace Flow.Launcher.Core.Plugin StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath); await base.InitAsync(context); } + + protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.HeaderDelimited; } } diff --git a/Flow.Launcher.Core/Plugin/PythonPluginV2.cs b/Flow.Launcher.Core/Plugin/PythonPluginV2.cs index f768daf15..5c36e0eea 100644 --- a/Flow.Launcher.Core/Plugin/PythonPluginV2.cs +++ b/Flow.Launcher.Core/Plugin/PythonPluginV2.cs @@ -19,13 +19,10 @@ namespace Flow.Launcher.Core.Plugin internal sealed class PythonPluginV2 : ProcessStreamPluginV2 { protected override ProcessStartInfo StartInfo { get; set; } - + public PythonPluginV2(string filename) { - StartInfo = new ProcessStartInfo - { - FileName = filename, - }; + StartInfo = new ProcessStartInfo { FileName = filename, }; var path = Path.Combine(Constant.ProgramDirectory, JsonRpc); StartInfo.EnvironmentVariables["PYTHONPATH"] = path; @@ -33,11 +30,13 @@ namespace Flow.Launcher.Core.Plugin //Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable StartInfo.ArgumentList.Add("-B"); } - + public override async Task InitAsync(PluginInitContext context) { StartInfo.ArgumentList.Add(context.CurrentPluginMetadata.ExecuteFilePath); await base.InitAsync(context); } + + protected override MessageHandlerType MessageHandler { get; } = MessageHandlerType.NewLineDelimited; } }