Skip to content

Commit bd9a530

Browse files
authored
Merge pull request #2453 from Flow-Launcher/jsonrpcv2
JsonRPCV2 Small revision
2 parents 9dcbb18 + bdc9d02 commit bd9a530

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

Flow.Launcher.Core/Flow.Launcher.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<PackageReference Include="FSharp.Core" Version="7.0.401" />
5858
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
5959
<PackageReference Include="squirrel.windows" Version="1.5.2" NoWarn="NU1701" />
60-
<PackageReference Include="StreamJsonRpc" Version="2.16.36" />
60+
<PackageReference Include="StreamJsonRpc" Version="2.17.8" />
6161
</ItemGroup>
6262

6363
<ItemGroup>

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class JsonRPCPluginSettings
1515

1616
public required string SettingPath { get; init; }
1717
public Dictionary<string, FrameworkElement> SettingControls { get; } = new();
18-
18+
1919
public IReadOnlyDictionary<string, object> Inner => Settings;
2020
protected ConcurrentDictionary<string, object> Settings { get; set; }
2121
public required IPublicAPI API { get; init; }
22-
22+
2323
private JsonStorage<ConcurrentDictionary<string, object>> _storage;
2424

2525
// maybe move to resource?
@@ -37,26 +37,26 @@ public async Task InitializeAsync()
3737
_storage = new JsonStorage<ConcurrentDictionary<string, object>>(SettingPath);
3838
Settings = await _storage.LoadAsync();
3939

40-
if (Settings != null)
40+
if (Settings != null || Configuration == null)
4141
{
4242
return;
4343
}
4444

45-
foreach (var (type, attributes) in Configuration.Body)
45+
foreach (var (type, attributes) in Configuration.Body)
4646
{
4747
if (attributes.Name == null)
4848
{
4949
continue;
5050
}
51-
51+
5252
if (!Settings.ContainsKey(attributes.Name))
5353
{
5454
Settings[attributes.Name] = attributes.DefaultValue;
5555
}
5656
}
5757
}
5858

59-
59+
6060
public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
6161
{
6262
if (settings == null || settings.Count == 0)
@@ -80,34 +80,35 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
8080
comboBox.Dispatcher.Invoke(() => comboBox.SelectedItem = value);
8181
break;
8282
case CheckBox checkBox:
83-
checkBox.Dispatcher.Invoke(() => checkBox.IsChecked = value is bool isChecked ? isChecked : bool.Parse(value as string ?? string.Empty));
83+
checkBox.Dispatcher.Invoke(() =>
84+
checkBox.IsChecked = value is bool isChecked
85+
? isChecked
86+
: bool.Parse(value as string ?? string.Empty));
8487
break;
8588
}
8689
}
8790
}
91+
8892
Save();
8993
}
90-
94+
9195
public async Task SaveAsync()
9296
{
9397
await _storage.SaveAsync();
9498
}
95-
99+
96100
public void Save()
97101
{
98102
_storage.Save();
99103
}
100-
104+
101105
public Control CreateSettingPanel()
102106
{
103-
if (Settings == null)
107+
if (Settings == null || Settings.Count == 0)
104108
return new();
105109

106110
var settingWindow = new UserControl();
107-
var mainPanel = new Grid
108-
{
109-
Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center
110-
};
111+
var mainPanel = new Grid { Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center };
111112

112113
ColumnDefinition gridCol1 = new ColumnDefinition();
113114
ColumnDefinition gridCol2 = new ColumnDefinition();
@@ -242,10 +243,7 @@ public Control CreateSettingPanel()
242243
Margin = new Thickness(10, 0, 0, 0), Content = "Browse"
243244
};
244245

245-
var dockPanel = new DockPanel()
246-
{
247-
Margin = settingControlMargin
248-
};
246+
var dockPanel = new DockPanel() { Margin = settingControlMargin };
249247

250248
DockPanel.SetDock(Btn, Dock.Right);
251249
dockPanel.Children.Add(Btn);
@@ -352,7 +350,10 @@ public Control CreateSettingPanel()
352350
case "checkbox":
353351
var checkBox = new CheckBox
354352
{
355-
IsChecked = Settings[attribute.Name] is bool isChecked ? isChecked : bool.Parse(attribute.DefaultValue),
353+
IsChecked =
354+
Settings[attribute.Name] is bool isChecked
355+
? isChecked
356+
: bool.Parse(attribute.DefaultValue),
356357
Margin = settingCheckboxMargin,
357358
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
358359
ToolTip = attribute.Description
@@ -375,14 +376,12 @@ public Control CreateSettingPanel()
375376

376377
break;
377378
case "hyperlink":
378-
var hyperlink = new Hyperlink
379-
{
380-
ToolTip = attribute.Description, NavigateUri = attribute.url
381-
};
379+
var hyperlink = new Hyperlink { ToolTip = attribute.Description, NavigateUri = attribute.url };
382380

383381
var linkbtn = new System.Windows.Controls.Button
384382
{
385-
HorizontalAlignment = System.Windows.HorizontalAlignment.Right, Margin = settingControlMargin
383+
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
384+
Margin = settingControlMargin
386385
};
387386

388387
linkbtn.Content = attribute.urlLabel;
@@ -408,12 +407,9 @@ public Control CreateSettingPanel()
408407
mainPanel.Children.Add(panel);
409408
mainPanel.Children.Add(contentControl);
410409
rowCount++;
411-
412410
}
413411

414412
return settingWindow;
415413
}
416-
417-
418414
}
419415
}

Flow.Launcher.Core/Plugin/JsonRPCPluginV2.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async Task ReadErrorAsync()
9191

9292
private void SetupJsonRPC()
9393
{
94-
var formatter = new JsonMessageFormatter();
94+
var formatter = new SystemTextJsonFormatter { JsonSerializerOptions = RequestSerializeOption };
9595
var handler = new NewLineDelimitedMessageHandler(ClientPipe,
9696
formatter);
9797

@@ -100,10 +100,8 @@ private void SetupJsonRPC()
100100
RPC.AddLocalRpcMethod("UpdateResults", new Action<string, JsonRPCQueryResponseModel>((rawQuery, response) =>
101101
{
102102
var results = ParseResults(response);
103-
ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs { Query = new Query()
104-
{
105-
RawQuery = rawQuery
106-
}, Results = results });
103+
ResultsUpdated?.Invoke(this,
104+
new ResultUpdatedEventArgs { Query = new Query() { RawQuery = rawQuery }, Results = results });
107105
}));
108106
RPC.SynchronizationContext = null;
109107
RPC.StartListening();

0 commit comments

Comments
 (0)