Skip to content

Commit 077edec

Browse files
committed
PluginSettingsWindow: Change API Method to check for existing windows with the same plugin id and reuse
1 parent 633d3c7 commit 077edec

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ public interface IPublicAPI
164164

165165

166166
/// <summary>
167-
/// Open plugin setting window for a specific plugin
167+
/// Open plugin setting window for a specific plugin.
168+
/// Reuses the existing window when that plugin's settings window is already open.
168169
/// </summary>
169170
/// <param name="pluginId">ID of the plugin whose settings window should be opened</param>
170-
/// <returns>True if the plugin settings window was successfully opened; false otherwise</returns>
171+
/// <returns>True if the plugin settings window was successfully opened or reused; false otherwise</returns>
171172
bool OpenPluginSettingsWindow(string pluginId);
172173

173174
/// <summary>

Flow.Launcher/PluginSettingsWindow.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public partial class PluginSettingsWindow
1313
{
1414
private readonly Settings _settings;
1515

16+
public string PluginId { get; }
17+
1618
public PluginSettingsWindow(string pluginId)
1719
{
1820
_settings = Ioc.Default.GetRequiredService<Settings>();
@@ -21,6 +23,8 @@ public PluginSettingsWindow(string pluginId)
2123
throw new ArgumentException("Plugin ID cannot be null or whitespace.", nameof(pluginId));
2224
}
2325

26+
PluginId = pluginId;
27+
2428
var pluginPair = PluginManager.GetPluginForId(pluginId);
2529
if (pluginPair == null)
2630
{

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.ComponentModel;
66
using System.Diagnostics;
77
using System.IO;
8+
using System.Linq;
89
using System.Net;
910
using System.Runtime.CompilerServices;
1011
using System.Runtime.InteropServices;
@@ -153,8 +154,27 @@ public bool OpenPluginSettingsWindow(string pluginId)
153154
{
154155
try
155156
{
156-
var window = new PluginSettingsWindow(pluginId);
157-
window.Show();
157+
// get existing settings window for this plugin, or else create a new one
158+
var window = Application.Current.Windows
159+
.OfType<PluginSettingsWindow>()
160+
.FirstOrDefault(existing => existing.PluginId == pluginId)
161+
?? new PluginSettingsWindow(pluginId);
162+
163+
if (window.WindowState == WindowState.Minimized)
164+
{
165+
window.WindowState = WindowState.Normal;
166+
}
167+
168+
if (!window.IsVisible)
169+
{
170+
window.Show();
171+
}
172+
else
173+
{
174+
window.Activate();
175+
}
176+
177+
window.Focus();
158178
return true;
159179
}
160180
catch (Exception e)

0 commit comments

Comments
 (0)