Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AuthenticatorChooser/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public int OnExecute() {
logger.Info("Operating system is {name} {marketingVersion} {version} {arch}", os.name, os.marketingVersion, os.version, os.architecture);
logger.Info("{Locales are} {locales}", I18N.LOCALE_NAMES.Count == 1 ? "Locale is" : "Locales are", string.Join(", ", I18N.LOCALE_NAMES));

using TrayIcon trayIcon = new TrayIcon(() => { EXITING_TRIGGER.Cancel(); Application.Exit(); });
using WindowOpeningListener windowOpeningListener = new WindowOpeningListenerImpl();
WindowsSecurityKeyChooser securityKeyChooser = new(new ChooserOptions(skipAllNonSecurityKeyOptions, autosubmitPinLength));
WindowsSecurityKeyChooser securityKeyChooser = new(new ChooserOptions(skipAllNonSecurityKeyOptions, autosubmitPinLength), trayIcon);

windowOpeningListener.windowOpened += (_, window) => securityKeyChooser.chooseUsbSecurityKey(window);

Expand Down
41 changes: 41 additions & 0 deletions AuthenticatorChooser/TrayIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Drawing;
using System.Windows.Forms;

namespace AuthenticatorChooser;

public class TrayIcon: IDisposable {

private readonly NotifyIcon notifyIcon;
private readonly ToolStripMenuItem enabledMenuItem;

public bool isEnabled => enabledMenuItem.Checked;

public TrayIcon(Action onExit) {
enabledMenuItem = new ToolStripMenuItem("Enabled") {
Checked = true,
CheckOnClick = true
};

ToolStripMenuItem exitMenuItem = new("Exit");
exitMenuItem.Click += (_, _) => onExit();

ContextMenuStrip contextMenu = new();
contextMenu.Items.Add(enabledMenuItem);
contextMenu.Items.Add(new ToolStripSeparator());
contextMenu.Items.Add(exitMenuItem);

notifyIcon = new NotifyIcon {
Text = nameof(AuthenticatorChooser),
Icon = Icon.ExtractAssociatedIcon(Environment.ProcessPath!)!,
ContextMenuStrip = contextMenu,
Visible = true
};
}

public void Dispose() {
notifyIcon.Visible = false;
notifyIcon.Dispose();
GC.SuppressFinalize(this);
}

}
4 changes: 2 additions & 2 deletions AuthenticatorChooser/Windows11/WindowsSecurityKeyChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace AuthenticatorChooser.Windows11;

public class WindowsSecurityKeyChooser(ChooserOptions options): AbstractSecurityKeyChooser<SystemWindow> {
public class WindowsSecurityKeyChooser(ChooserOptions options, TrayIcon trayIcon): AbstractSecurityKeyChooser<SystemWindow> {

// #4: unfortunately, this class name is shared with the UAC prompt, detectable when desktop dimming is disabled
private const string WINDOW_CLASS_NAME = "Credential Dialog Xaml Host";
Expand Down Expand Up @@ -71,7 +71,7 @@ public override void chooseUsbSecurityKey(SystemWindow fidoPrompt) {

bool isShiftDown = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);

strategy.handleWindow(actualTitle!, fidoEl, outerScrollViewer, isShiftDown);
strategy.handleWindow(actualTitle!, fidoEl, outerScrollViewer, isShiftDown || !trayIcon.isEnabled);

} catch (ElementNotAvailableException e) {
LOGGER.Error(e, "Element in Windows Security dialog box disappeared before this program could interact with it, skipping this dialog box instance");
Expand Down