Skip to content

Commit bfdf565

Browse files
authored
Merge pull request #3300 from Jack251970/settings_panel_double_creation
Remove unneccessary CreateSettingPanel by introducing need check
2 parents 57f20ae + 4e47586 commit bfdf565

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Flow.Launcher.Core.Plugin
3434
/// Represent the plugin that using JsonPRC
3535
/// every JsonRPC plugin should has its own plugin instance
3636
/// </summary>
37-
internal abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISettingProvider, ISavable
37+
public abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISettingProvider, ISavable
3838
{
3939
protected PluginInitContext Context;
4040
public const string JsonRPC = "JsonRPC";
@@ -157,6 +157,11 @@ public void Save()
157157
Settings?.Save();
158158
}
159159

160+
public bool NeedCreateSettingPanel()
161+
{
162+
return Settings.NeedCreateSettingPanel();
163+
}
164+
160165
public Control CreateSettingPanel()
161166
{
162167
return Settings.CreateSettingPanel();

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ public void Save()
109109
_storage.Save();
110110
}
111111

112+
public bool NeedCreateSettingPanel()
113+
{
114+
// If there are no settings or the settings configuration is empty, return null
115+
return Settings != null && Configuration != null && Configuration.Body.Count != 0;
116+
}
117+
112118
public Control CreateSettingPanel()
113119
{
114-
if (Settings == null || Settings.Count == 0)
115-
return null;
120+
// No need to check if NeedCreateSettingPanel is true because CreateSettingPanel will only be called if it's true
116121

117122
var settingWindow = new UserControl();
118123
var mainPanel = new Grid { Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center };

Flow.Launcher/ViewModel/PluginViewModel.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public bool IsExpanded
9090
private Control _bottomPart2;
9191
public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginDisplayBottomData() : null;
9292

93-
public bool HasSettingControl => PluginPair.Plugin is ISettingProvider settingProvider && settingProvider.CreateSettingPanel() != null;
93+
public bool HasSettingControl => PluginPair.Plugin is ISettingProvider && (PluginPair.Plugin is not JsonRPCPluginBase jsonRPCPluginBase || jsonRPCPluginBase.NeedCreateSettingPanel());
9494
public Control SettingControl
9595
=> IsExpanded
9696
? _settingControl
97-
??= PluginPair.Plugin is not ISettingProvider settingProvider
98-
? null
99-
: settingProvider.CreateSettingPanel()
97+
??= HasSettingControl
98+
? ((ISettingProvider)PluginPair.Plugin).CreateSettingPanel()
99+
: null
100100
: null;
101101
private ImageSource _image = ImageLoader.MissingImage;
102102

0 commit comments

Comments
 (0)