|
24 | 24 | TYPE_DELAY_MS = 100 |
25 | 25 | PRE_ENTER_DELAY = 1 |
26 | 26 | XDOTOOL_TIMEOUT = 10 |
27 | | -MIN_TOTP_SECONDS_REMAINING = 8 |
| 27 | +MIN_TOTP_SECONDS_REMAINING = 15 |
28 | 28 | MAX_AUTOFILL_SUBMISSIONS_RAW = os.environ.get("IBKR_2FA_MAX_SUBMISSIONS", "1") |
29 | 29 |
|
30 | 30 | # Window titles to search for 2FA prompts. Live IBKR accounts can show mobile |
@@ -207,6 +207,15 @@ def focus_input_area(candidate): |
207 | 207 | run_xdotool(["windowfocus", "--sync", candidate.window_id]) |
208 | 208 | run_xdotool(["mousemove", "--window", candidate.window_id, str(x), str(y)]) |
209 | 209 | run_xdotool(["click", "1"]) |
| 210 | + time.sleep(0.2) |
| 211 | + |
| 212 | + |
| 213 | +def type_totp_into_active_window(code): |
| 214 | + """Type into the focused control; Java dialogs can ignore direct window events.""" |
| 215 | + run_xdotool(["key", "ctrl+a", "BackSpace"]) |
| 216 | + run_xdotool(["type", "--delay", str(TYPE_DELAY_MS), code], sensitive=True) |
| 217 | + time.sleep(PRE_ENTER_DELAY) |
| 218 | + run_xdotool(["key", "Return"]) |
210 | 219 |
|
211 | 220 |
|
212 | 221 | def submit_totp(candidate): |
@@ -246,14 +255,7 @@ def submit_totp(candidate): |
246 | 255 |
|
247 | 256 | focus_input_area(candidate) |
248 | 257 | code = get_totp() |
249 | | - |
250 | | - run_xdotool(["key", "--window", candidate.window_id, "ctrl+a", "BackSpace"]) |
251 | | - run_xdotool( |
252 | | - ["type", "--window", candidate.window_id, "--delay", str(TYPE_DELAY_MS), code], |
253 | | - sensitive=True, |
254 | | - ) |
255 | | - time.sleep(PRE_ENTER_DELAY) |
256 | | - run_xdotool(["key", "--window", candidate.window_id, "Return"]) |
| 258 | + type_totp_into_active_window(code) |
257 | 259 |
|
258 | 260 | autofill_submission_count += 1 |
259 | 261 | log.info("Auto-fill submitted, waiting for gateway response...") |
|
0 commit comments