From ddc6af52ed4fba8d1e7779c52c4a127e7ff5d964 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sat, 13 Nov 2021 23:48:53 -0600 Subject: [PATCH] Allow modifying Setting via result --- Flow.Launcher.Core/Plugin/JsonPRCModel.cs | 2 + Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs | 56 ++++------------------ 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs index 4ec25a843..cf75e4aa3 100644 --- a/Flow.Launcher.Core/Plugin/JsonPRCModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonPRCModel.cs @@ -90,5 +90,7 @@ namespace Flow.Launcher.Core.Plugin public class JsonRPCResult : Result { public JsonRPCClientRequestModel JsonRPCAction { get; set; } + + public Dictionary SettingsChange { get; set; } } } \ No newline at end of file diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index 255499efd..fb8c0c4f0 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -109,6 +109,14 @@ namespace Flow.Launcher.Core.Plugin { result.Action = c => { + if (result.SettingsChange is not null) + { + foreach (var (key, value) in result.SettingsChange) + { + Settings[key] = value; + } + } + if (result.JsonRPCAction == null) return false; if (string.IsNullOrEmpty(result.JsonRPCAction.Method)) @@ -442,54 +450,6 @@ namespace Flow.Launcher.Core.Plugin panel.Children.Add(contentControl); mainPanel.Children.Add(panel); } - - // foreach (var (key, value) in Settings) - // { - // var panel = new StackPanel - // { - // Orientation = Orientation.Horizontal, Margin = settingControlMargin - // }; - // var name = new Label - // { - // Content = key, VerticalAlignment = VerticalAlignment.Center - // }; - // UIElement content = null; - // switch (value) - // { - // case int i: - // case double d: - // throw new TypeAccessException(); - // case string s: - // var textBox = new TextBox - // { - // Text = s, - // Margin = settingControlMargin, - // VerticalAlignment = VerticalAlignment.Center - // }; - // textBox.TextChanged += (_, _) => - // { - // Settings[key] = textBox.Text; - // }; - // content = textBox; - // break; - // case bool b: - // var checkBox = new CheckBox - // { - // IsChecked = b, - // Margin = settingControlMargin, - // VerticalAlignment = VerticalAlignment.Center - // }; - // checkBox.Click += (_, _) => - // { - // Settings[key] = checkBox.IsChecked; - // }; - // content = checkBox; - // break; - // default: - // throw new ArgumentOutOfRangeException(); - // } - // - // } return settingWindow; } public void Save()