| 1 | # The selector is deliberately scoped to the rendered transcript. Sidebar topic |
| 2 | # titles and offscreen accessibility nodes are not evidence of restored history. |
| 3 | function Get-UpgradeUIDescendants($element) { |
| 4 | return $element.FindAll([Windows.Automation.TreeScope]::Descendants, [Windows.Automation.Condition]::TrueCondition) |
| 5 | } |
| 6 | |
| 7 | function Invoke-UpgradeUIButton($element) { |
| 8 | $pattern = $element.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern) |
| 9 | $pattern.Invoke() |
| 10 | } |
| 11 | |
| 12 | function Invoke-PendingHistoricalSession($root) { |
| 13 | foreach ($element in (Get-UpgradeUIDescendants $root)) { |
| 14 | $current = $element.Current |
| 15 | if ($current.AutomationId -eq 'reasonix-prepare-restored-session' -and -not $current.IsOffscreen -and |
| 16 | $current.BoundingRectangle.Width -gt 0 -and $current.BoundingRectangle.Height -gt 0) { |
| 17 | Invoke-UpgradeUIButton $element |
| 18 | return $true |
| 19 | } |
| 20 | } |
| 21 | return $false |
| 22 | } |
| 23 | |
| 24 | function Test-VisibleUpgradeHistory($root, [string]$text) { |
| 25 | if ([string]::IsNullOrWhiteSpace($text)) { return $false } |
| 26 | $descendants = @(Get-UpgradeUIDescendants $root) |
| 27 | foreach ($element in $descendants) { |
| 28 | $current = $element.Current |
| 29 | if ($current.IsOffscreen -or $current.BoundingRectangle.Width -le 0 -or $current.BoundingRectangle.Height -le 0) { continue } |
| 30 | # Old content alone cannot prove recovery: reject a still-loading/failed |
| 31 | # recovery surface and the obsolete chat notice that originally hid this bug. |
| 32 | if (([string]$current.AutomationId).StartsWith('reasonix-session-recovery-') -or |
| 33 | $current.AutomationId -eq 'reasonix-prepare-restored-session' -or |
| 34 | ([string]$current.Name).Contains('Failed to load conversation history.') -or |
| 35 | ([string]$current.Name).Contains('加载会话历史失败。') -or |
| 36 | ([string]$current.Name).Contains('載入會話歷史失敗。')) { return $false } |
| 37 | } |
| 38 | foreach ($transcript in $descendants) { |
| 39 | if (-not ([string]$transcript.Current.AutomationId).StartsWith('reasonix-chat-transcript-') -or $transcript.Current.IsOffscreen) { continue } |
| 40 | foreach ($element in (Get-UpgradeUIDescendants $transcript)) { |
| 41 | $current = $element.Current |
| 42 | if (-not $current.IsOffscreen -and $current.BoundingRectangle.Width -gt 0 -and $current.BoundingRectangle.Height -gt 0 -and |
| 43 | $current.Name.Contains($text)) { return $true } |
| 44 | } |
| 45 | } |
| 46 | return $false |
| 47 | } |
| 48 |