Skip to content
Open
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
22 changes: 21 additions & 1 deletion Tools/windows/uia-live-gate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1002,13 +1002,33 @@ try {
# busy runner more headroom to let the app's own focus-reassertion converge.
for ($index = 0; $index -lt 600; $index++) {
$null = [GraphCodeUiaGateState]::ActivateWindow($shellWindow)
# A delayed, activation-driven refocus has been observed to re-target the workspace's Text
# Area shortly after ActivateWindow returns. Settle briefly so our SetFocus below lands after
# that reassertion, rather than being immediately overwritten by it before we sample focus.
Start-Sleep -Milliseconds 40
$safeFocusRow.SetFocus()
Start-Sleep -Milliseconds 50
$candidate = [System.Windows.Automation.AutomationElement]::FocusedElement
if ($candidate.Current.AutomationId -eq $safeRowId) {
$focused = $candidate
break
}
Start-Sleep -Milliseconds 10
}
if ($null -eq $focused) {
# Final bounded nudge: give the foreground transition a longer settle window than any single
# polling iteration above, reassert focus once more, and recheck before failing with
# diagnostic focus data. This does not change the overall ~30s budget of the loop above.
$null = [GraphCodeUiaGateState]::ActivateWindow($shellWindow)
Start-Sleep -Milliseconds 300
$safeFocusRow.SetFocus()
for ($index = 0; $index -lt 4; $index++) {
$candidate = [System.Windows.Automation.AutomationElement]::FocusedElement
if ($candidate.Current.AutomationId -eq $safeRowId) {
$focused = $candidate
break
}
Start-Sleep -Milliseconds 50
}
}
Require ($null -ne $focused) "worktree row could not retain focus against concurrent desktop focus changes; focused=$($candidate.Current.AutomationId):$($candidate.Current.Name)"
Require ($focused.Current.AutomationId -eq $safeRowId) "focus source identity was '$($focused.Current.AutomationId)', expected '$safeRowId'"
Expand Down
Loading