Skip to content

Commit d3fdd99

Browse files
committed
Fix ConnectionLostException for JsonRPC v2 plugins
1 parent 2e740b1 commit d3fdd99

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
using Flow.Launcher.Core.Resource;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Diagnostics;
54
using System.IO;
65
using System.Text;
76
using System.Text.Json;
87
using System.Threading;
98
using System.Threading.Tasks;
9+
using Flow.Launcher.Core.Resource;
1010
using Flow.Launcher.Infrastructure.Logger;
1111
using Flow.Launcher.Plugin;
1212
using Microsoft.IO;
13-
using System.Windows;
1413

1514
namespace Flow.Launcher.Core.Plugin
1615
{
@@ -20,7 +19,7 @@ namespace Flow.Launcher.Core.Plugin
2019
/// </summary>
2120
internal abstract class JsonRPCPlugin : JsonRPCPluginBase
2221
{
23-
public const string JsonRPC = "JsonRPC";
22+
public new const string JsonRPC = "JsonRPC";
2423

2524
protected abstract Task<Stream> RequestAsync(JsonRPCRequestModel rpcRequest, CancellationToken token = default);
2625
protected abstract string Request(JsonRPCRequestModel rpcRequest, CancellationToken token = default);
@@ -29,9 +28,6 @@ internal abstract class JsonRPCPlugin : JsonRPCPluginBase
2928

3029
private int RequestId { get; set; }
3130

32-
private string SettingConfigurationPath => Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "SettingsTemplate.yaml");
33-
private string SettingPath => Path.Combine(Context.CurrentPluginMetadata.PluginSettingsDirectoryPath, "Settings.json");
34-
3531
public override List<Result> LoadContextMenus(Result selectedResult)
3632
{
3733
var request = new JsonRPCRequestModel(RequestId++,
@@ -57,13 +53,6 @@ public override List<Result> LoadContextMenus(Result selectedResult)
5753
}
5854
};
5955

60-
private static readonly JsonSerializerOptions settingSerializeOption = new()
61-
{
62-
WriteIndented = true
63-
};
64-
65-
private readonly Dictionary<string, FrameworkElement> _settingControls = new();
66-
6756
private async Task<List<Result>> DeserializedResultAsync(Stream output)
6857
{
6958
await using (output)
@@ -122,7 +111,6 @@ protected override async Task<bool> ExecuteResultAsync(JsonRPCResult result)
122111
return !result.JsonRPCAction.DontHideAfterAction;
123112
}
124113

125-
126114
/// <summary>
127115
/// Execute external program and return the output
128116
/// </summary>

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Flow.Launcher.Core.Resource;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.IO;
54
using System.Linq;
65
using System.Text.Json;
76
using System.Threading;
87
using System.Threading.Tasks;
8+
using Flow.Launcher.Core.Resource;
99
using Flow.Launcher.Plugin;
1010
using YamlDotNet.Serialization;
1111
using YamlDotNet.Serialization.NamingConventions;

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using StreamJsonRpc;
1111
using IAsyncDisposable = System.IAsyncDisposable;
1212

13-
1413
namespace Flow.Launcher.Core.Plugin
1514
{
1615
internal abstract class JsonRPCPluginV2 : JsonRPCPluginBase, IAsyncDisposable, IAsyncReloadable, IResultUpdated
@@ -23,7 +22,6 @@ internal abstract class JsonRPCPluginV2 : JsonRPCPluginBase, IAsyncDisposable, I
2322

2423
private JsonRpc RPC { get; set; }
2524

26-
2725
protected override async Task<bool> ExecuteResultAsync(JsonRPCResult result)
2826
{
2927
var res = await RPC.InvokeAsync<JsonRPCExecuteResponse>(result.JsonRPCAction.Method,
@@ -55,7 +53,6 @@ public override async Task<List<Result>> QueryAsync(Query query, CancellationTok
5553
return results;
5654
}
5755

58-
5956
public override async Task InitAsync(PluginInitContext context)
6057
{
6158
await base.InitAsync(context);
@@ -88,7 +85,6 @@ protected enum MessageHandlerType
8885

8986
protected abstract MessageHandlerType MessageHandler { get; }
9087

91-
9288
private void SetupJsonRPC()
9389
{
9490
var formatter = new SystemTextJsonFormatter { JsonSerializerOptions = RequestSerializeOption };
@@ -118,9 +114,16 @@ public virtual async Task ReloadDataAsync()
118114
{
119115
await RPC.InvokeAsync("reload_data", Context);
120116
}
121-
catch (RemoteMethodNotFoundException e)
117+
catch (RemoteMethodNotFoundException)
118+
{
119+
}
120+
catch (ConnectionLostException)
122121
{
123122
}
123+
catch (Exception e)
124+
{
125+
Context.API.LogException(nameof(JsonRPCPluginV2), "Failed to call reload_data", e);
126+
}
124127
}
125128

126129
public virtual async ValueTask DisposeAsync()
@@ -129,8 +132,15 @@ public virtual async ValueTask DisposeAsync()
129132
{
130133
await RPC.InvokeAsync("close");
131134
}
132-
catch (RemoteMethodNotFoundException e)
135+
catch (RemoteMethodNotFoundException)
136+
{
137+
}
138+
catch (ConnectionLostException)
139+
{
140+
}
141+
catch (Exception e)
133142
{
143+
Context.API.LogException(nameof(JsonRPCPluginV2), "Failed to call close", e);
134144
}
135145
finally
136146
{

0 commit comments

Comments
 (0)