Skip to content

Commit 05104a5

Browse files
committed
Implement Setting back and forward transfer
1 parent 9cd3f90 commit 05104a5

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Flow.Launcher.Core/Plugin/JsonPRCModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class JsonRPCQueryResponseModel : JsonRPCResponseModel
4343
[JsonPropertyName("result")]
4444
public new List<JsonRPCResult> Result { get; set; }
4545

46+
public Dictionary<string, object> SettingsChange { get; set; }
47+
4648
public string DebugMessage { get; set; }
4749
}
4850

@@ -52,6 +54,8 @@ public class JsonRPCRequestModel
5254

5355
public object[] Parameters { get; set; }
5456

57+
public Dictionary<string, object> Settings { get; set; }
58+
5559
private static readonly JsonSerializerOptions options = new()
5660
{
5761
PropertyNamingPolicy = JsonNamingPolicy.CamelCase

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ private List<Result> ParseResults(JsonRPCQueryResponseModel queryResponseModel)
148148

149149
results.AddRange(queryResponseModel.Result);
150150

151+
if (queryResponseModel.SettingsChange != null)
152+
{
153+
foreach (var (key, value) in queryResponseModel.SettingsChange)
154+
{
155+
Settings[key] = value;
156+
}
157+
}
158+
151159
return results;
152160
}
153161

@@ -300,10 +308,11 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
300308
var request = new JsonRPCRequestModel
301309
{
302310
Method = "query",
303-
Parameters = new[]
311+
Parameters = new object[]
304312
{
305313
query.Search
306-
}
314+
},
315+
Settings = Settings
307316
};
308317
var output = await RequestAsync(request, token);
309318
return await DeserializedResultAsync(output);
@@ -345,7 +354,8 @@ public Control CreateSettingPanel()
345354
var settingWindow = new UserControl();
346355
var mainPanel = new StackPanel
347356
{
348-
Margin = settingControlMargin, Orientation = Orientation.Vertical
357+
Margin = settingControlMargin,
358+
Orientation = Orientation.Vertical
349359
};
350360
settingWindow.Content = mainPanel;
351361

@@ -370,7 +380,8 @@ public Control CreateSettingPanel()
370380
{
371381
var textBox = new TextBox()
372382
{
373-
Width = 300, Text = Settings[attribute.Name] as string ?? string.Empty,
383+
Width = 300,
384+
Text = Settings[attribute.Name] as string ?? string.Empty,
374385
Margin = settingControlMargin
375386
};
376387
textBox.TextChanged += (_, _) =>
@@ -401,7 +412,8 @@ public Control CreateSettingPanel()
401412
{
402413
var comboBox = new ComboBox()
403414
{
404-
ItemsSource = attribute.Options, SelectedItem = Settings[attribute.Name],
415+
ItemsSource = attribute.Options,
416+
SelectedItem = Settings[attribute.Name],
405417
Margin = settingControlMargin
406418
};
407419
comboBox.SelectionChanged += (sender, _) =>
@@ -419,7 +431,7 @@ public Control CreateSettingPanel()
419431
};
420432
checkBox.Click += (sender, _) =>
421433
{
422-
Settings[attribute.Name] = ((CheckBox) sender).IsChecked;
434+
Settings[attribute.Name] = ((CheckBox)sender).IsChecked;
423435
};
424436
contentControl = checkBox;
425437
break;

0 commit comments

Comments
 (0)