Add support for concurrent operation of explorers & dialogs adding

This commit is contained in:
Jack251970 2025-07-21 14:03:45 +08:00
parent d4e672d630
commit c2157e2df1

View file

@ -13,6 +13,7 @@ using NHotkey;
using Windows.Win32; using Windows.Win32;
using Windows.Win32.Foundation; using Windows.Win32.Foundation;
using Windows.Win32.UI.Accessibility; using Windows.Win32.UI.Accessibility;
using System.Collections.Concurrent;
namespace Flow.Launcher.Infrastructure.DialogJump namespace Flow.Launcher.Infrastructure.DialogJump
{ {
@ -64,12 +65,12 @@ namespace Flow.Launcher.Infrastructure.DialogJump
private static HWND _mainWindowHandle = HWND.Null; private static HWND _mainWindowHandle = HWND.Null;
private static readonly Dictionary<DialogJumpExplorerPair, IDialogJumpExplorerWindow> _dialogJumpExplorers = new(); private static readonly ConcurrentDictionary<DialogJumpExplorerPair, IDialogJumpExplorerWindow> _dialogJumpExplorers = new();
private static DialogJumpExplorerPair _lastExplorer = null; private static DialogJumpExplorerPair _lastExplorer = null;
private static readonly object _lastExplorerLock = new(); private static readonly object _lastExplorerLock = new();
private static readonly Dictionary<DialogJumpDialogPair, IDialogJumpDialogWindow> _dialogJumpDialogs = new(); private static readonly ConcurrentDictionary<DialogJumpDialogPair, IDialogJumpDialogWindow> _dialogJumpDialogs = new();
private static IDialogJumpDialogWindow _dialogWindow = null; private static IDialogJumpDialogWindow _dialogWindow = null;
private static readonly object _dialogWindowLock = new(); private static readonly object _dialogWindowLock = new();
@ -105,22 +106,13 @@ namespace Flow.Launcher.Infrastructure.DialogJump
#region Initialize & Setup #region Initialize & Setup
public static void InitializeDialogJump(IList<DialogJumpExplorerPair> dialogJumpExplorers, public static void InitializeDialogJump()
IList<DialogJumpDialogPair> dialogJumpDialogs)
{ {
if (_initialized) return; if (_initialized) return;
// Initialize Dialog Jump explorers & dialogs // Initialize preinstalled Dialog Jump explorers & dialogs
_dialogJumpExplorers.Add(WindowsDialogJumpExplorer, null); _dialogJumpExplorers.TryAdd(WindowsDialogJumpExplorer, null);
foreach (var explorer in dialogJumpExplorers) _dialogJumpDialogs.TryAdd(WindowsDialogJumpDialog, null);
{
_dialogJumpExplorers.Add(explorer, null);
}
_dialogJumpDialogs.Add(WindowsDialogJumpDialog, null);
foreach (var dialog in dialogJumpDialogs)
{
_dialogJumpDialogs.Add(dialog, null);
}
// Initialize main window handle // Initialize main window handle
_mainWindowHandle = Win32Helper.GetMainWindowHandle(); _mainWindowHandle = Win32Helper.GetMainWindowHandle();
@ -135,6 +127,29 @@ namespace Flow.Launcher.Infrastructure.DialogJump
_initialized = true; _initialized = true;
} }
public static void InitializeDialogJumpPlugin(PluginPair pair)
{
// Add Dialog Jump explorers & dialogs
if (pair.Plugin is IDialogJumpExplorer explorer)
{
var dialogJumpExplorer = new DialogJumpExplorerPair
{
Plugin = explorer,
Metadata = pair.Metadata
};
_dialogJumpExplorers.TryAdd(dialogJumpExplorer, null);
}
else if (pair.Plugin is IDialogJumpDialog dialog)
{
var dialogJumpDialog = new DialogJumpDialogPair
{
Plugin = dialog,
Metadata = pair.Metadata
};
_dialogJumpDialogs.TryAdd(dialogJumpDialog, null);
}
}
public static void SetupDialogJump(bool enabled) public static void SetupDialogJump(bool enabled)
{ {
if (enabled == _enabled) return; if (enabled == _enabled) return;