diff --git a/src/KeePassWinHelloExt.cs b/src/KeePassWinHelloExt.cs index a2cd786..4db522f 100644 --- a/src/KeePassWinHelloExt.cs +++ b/src/KeePassWinHelloExt.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Drawing; using System.Reflection; +using System.Windows.Forms; using KeePass.Forms; using KeePass.Plugins; using KeePass.UI; @@ -113,6 +114,13 @@ private void OnWindowAdded(object sender, GwmWindowEventArgs e) } } + var autoTypeCtxForm = e.Form as AutoTypeCtxForm; + if (autoTypeCtxForm != null) + { + BringAutoTypeSelectionToFront(autoTypeCtxForm); + return; + } + var optionsForm = e.Form as OptionsForm; if (optionsForm != null) { @@ -129,5 +137,44 @@ private void OnWindowAdded(object sender, GwmWindowEventArgs e) _uiContextManager.CurrentContext.ShowError(ex); } } + + private static void BringAutoTypeSelectionToFront(AutoTypeCtxForm autoTypeCtxForm) + { + try + { + autoTypeCtxForm.BeginInvoke(new MethodInvoker(delegate + { + try + { + if (autoTypeCtxForm.IsDisposed) + return; + + var window = Win32Window.From(autoTypeCtxForm.Handle); + if (window != null) + window.EnsureForeground(); + + bool topMost = autoTypeCtxForm.TopMost; + try + { + autoTypeCtxForm.TopMost = true; + autoTypeCtxForm.BringToFront(); + autoTypeCtxForm.Activate(); + } + finally + { + autoTypeCtxForm.TopMost = topMost; + } + } + catch (Exception ex) + { + Debug.Fail(ex.Message); + } + })); + } + catch (Exception ex) + { + Debug.Fail(ex.Message); + } + } } }