dlech / KeeAgent

ssh agent plugin for KeePass 2.x
http://lechnology.com/software/keeagent
Other
530 stars 35 forks source link

[enhancement] focus of key-verification popup #231

Closed r2evans closed 4 months ago

r2evans commented 6 years ago

I have selected "Always require user confirmation...". When the popup appears, it is not Windows-focused, which means my normally keyboard-centric workflow is disrupted in order to select the window; at that point, I can left-key or Alt-Y my affirmation.

Is there a way to force making this popup be the Windows focus?

Reproduction:

  1. open git-for-windows bash;
  2. initiate a connection somewhere, e.g., using ssh, scp, or rsync (not within GfW);
  3. popup appears, but is not the focus.

KeePass-2.38; KeeAgent-0.10.1.0; Win10pro; GfW-2.17.0

dlech commented 6 years ago

It is supposed to be since #180.

r2evans commented 6 years ago

Ok, I'll work on a better reproduction, as it is now working (no changes, no restarts), but I know it has not been focused earlier today. Apologize for an incomplete reproduction.

dlech commented 6 years ago

I kind of have a feeling that this is Windows trying to be "smart" and not focus our application even though we requested it. I don't use Windows much but I have noticed that kind of behavior over the years with all applications.

r2evans commented 6 years ago

I was thinking the same thing, though I don't have experience programming the Windows-UI side of things. Thanks, I'll report back if I find anything notable.

r2evans commented 6 years ago

It's definitely not doing it all of the time: right now, it's always unfocused. It's the same from cmd.exe or Git bash (in a mintty), using ssh or scp. I can easily bring it into focus (mouse-click, Shift-Alt-Tab, or twice Win-8 (or which ever numbered icon KeePass is on the task bar)).

Is there something I can do to try to figure out what is different about this vice your code's intention? If there's a specific debug-able version of the plugin, I'll run that for you.

Edit: ... and 3 hours later, it's working again. I am not confident that this is entirely/mostly/at-all KeeAgent's fault, frankly: despite my best efforts at maintaining a clean laptop, Windows does at times decide to "be different". Fudge.

dlech commented 6 years ago

It should be pretty easy to clone this repo (git clone --recursive because of submodules) and run a debug version in Visual Studio if you want to.

Here is the code to look at: https://github.com/dlech/SshAgentLib/commit/844b487b0adeee8d8df777d9395f8dc9432ef2db

KuttKatrea commented 6 years ago

I have experienced the same problem "randomly" (it almost always works, but sometimes doesn't) but I haven't found the cause of that "sometimes"

I read somewhere that Windows tries not to give focus to background-started programs, maybe certain level of indirection (git command -> ssh) causes windows to recognize the window as a background-launched process?

r2evans commented 6 years ago

I can confirm that when an ssh-related processes connects for a key, if KeePass is the focus, then the popup is (so far 100%) in focus as well. When it is a different window (i.e., git bash), it is not so great.

In my on-again/off-again functioning, I'm currently in the "does not focus" mode, and I'm trying changes to window location, stacking order (other than KeePass-in-focus), maximized/visible/minimized, to no avail. However, when I deselect the option "Esc minimizes to tray...", the modal now has focus. @KuttKatrea , next time yours does not gain focus, can you check these settings and see if it changes the behavior?

(Side note: I'm finding that changes to "require user notification" does not always take effect immediately. It's a separate/new issue, but because of this behavior, my routine for trying to reproduce it is: change an option, lock, unlock, use ssh, etc.)

When I reselect those options the popup is still (for now) getting the focus, so perhaps it has something to do with KeePass' "minimization" methods (whether to tray or taskbar, not certain). If what KuttKatrea says (about background-started programs), perhaps the use of the tray may "taint" the program at some point.

(I just updated to win10 1803, no change in behavior from 1709.)

KuttKatrea commented 6 years ago

It has just happened to me, when using git in powershell running inside the IntelliJ Terminal.

Changing the "Esc minimizes to tray..." option did work for one git call on a cmd window once, then it stopped working again.

I'll try to keep testing

aXe1 commented 5 years ago

Similar problems: need to Alt+Shift+Tab every time the popup shows. If there are 2 consequent popup (ssh client is trying multiple keys), then only first is unfocused, all following would be ok. No difference from what ssh client call happens: Git Bash, WSL Bash, JetBrains DataGrip, Visual Studio Code, Total Commander.

Windows 10 (1809, 17763.316)
KeePass 2.4.1
KeeAgent 0.10.1
aXe1 commented 5 years ago

As a quick and dirty workaround I use AutoIt script:

While 1
  Local $hwnd = WinWait("KeePass", "has requested to use the SSH key")
  WinActivate($hwnd)
WEnd

Gist Precompiled x64 version

markkuleinio commented 2 years ago

This is still the number one problem in using KeeAgent. There is no apparent logic when the window opens in focus or not focused.

Here is another workaround (since Shift-Alt-Tab is not my favourite key combinations): Press Ctrl-Alt-K (or whatever is your hotkey for "Show KeePass window" in KeePass) and then Esc (to minimize KeePass), then the KeeAgent window gets the focus.

markkuleinio commented 2 years ago

FYI: Now that I've used Windows 11 (build 22000.778, KeePass 2.51.1, KeeAgent 0.12.1) for a few days, my initial experience is that KeeAgent does not suffer from the out-of-focus problem anymore.

r2evans commented 2 years ago

I just confirmed that it is still the same. I'm on Win11 (Build 22000.778), KeePass-2.51.1, KeeAgent-0.12.1. The original steps still reproduce the same symptom that the confirmation dialog is not windows-focused when it comes up.

markkuleinio commented 2 years ago

I don't know it that matters but I have the key selection dialog enabled, so it is shown first, and then the confirmation dialog. I configured KeePass and KeeAgent identically on Win10 and Win11.

As a side note, on that new Win11 laptop also Evernote Legacy works better (disclaimer: I'm not endorsing Evernote by any means, on the contrary): new note shortcut opens the note in focus. In general both Win10 (Lenovo X1 Carbon Gen 6) and Win11 (X1C Gen 10) laptops have the same apps installed with the same settings, as far as practically possible. No idea what could have affected these focus issues.

markkuleinio commented 1 year ago

After upgrading Windows 11 to 22H2 (build 22621.900) last week I have started to experience the same out-of-focus problems again. Sigh

dlech commented 7 months ago

FYI, I just merged a PR that changes the UI thread where the confirmation dialog runs. Not sure if it would make a difference in this issue, but if anyone wants to try the build from https://github.com/dlech/KeeAgent/actions/runs/7603541323 and see...

markkuleinio commented 7 months ago

if anyone wants to try the build from https://github.com/dlech/KeeAgent/actions/runs/7603541323 and see...

Tested 1.5 days now: 100% accuracy this far, no focus problems! 💪

Windows 11 22H2 (build 22621.3007)

The key list window opens in the main monitor though (instead of the monitor where the SSH key request was triggered), but I don't know how hard problem that would be to solve.

markkuleinio commented 7 months ago

Looks good based on day 3 with that build!

markkuleinio commented 4 months ago

Any plans to make a release with this feature?

dlech commented 4 months ago

Thanks for the reminder. I just released v0.13.7 so hopefully we can call this issue closed now.