TGViewer
Telegram github commits and releases Telegram github commits and releases @tgappsupdates · 4.55K subscribers
Post #20657 81
UnigramDev/Unigram/develop • d78de99 • 1 files, +15/-13
Track focus rather than window activation in ChooseCapturePopup (#3359)

The popup refreshes its list of capturable windows when the user comes back
from arranging the one they want to share. It reached that signal through
WindowContext.ForXamlRoot(XamlRoot).Activated, subscribed in Loaded and
detached in Unloaded, and both halves are unsafe:

- ForXamlRoot is a lookup in a dictionary the window is removed from when its
view is consolidated, even though the XAML tree is still alive, so it returns
null and the subscribe throws.
- XamlRoot is null by the time the popup unloads, and can throw on access, so
the detach throws too - and when it does, the handler is left attached to a
WindowContext that outlives the popup.

Focus tracks window activation just as reliably and needs neither. GotFocus is
raised when the window is activated and LostFocus when it is deactivated, so a
lost-then-got pair is the round trip worth refreshing on; a bare GotFocus is
not, since one arrives simply from opening the popup and enumerating every
window on the system is not free.

This is also the only ForXamlRoot call site in the app that dereferenced the
result directly - every other one assigns to a local and checks it.

Reported by crash telemetry on 12.9.1.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

#unigram
More from @tgappsupdates
  1. Oct 12, 2026UnigramDev/Unigram/accessibility-message-actions • 41dead6 • 1 files, +80/-0 Add keyboard…
  2. Oct 12, 2026UnigramDev/Unigram/accessibility-focus • d743272 • 8 files, +141/-0 Cycle window regions w…
  3. Oct 12, 2026UnigramDev/Unigram/accessibility-call-shortcuts • 629c069 • 3 files, +76/-1 Wire the call…
  4. Oct 12, 2026morethanwords/tweb/master • 85c1d93 • 50 files, +4704/-1435 Video chat: tiles on a stage,…
  5. Oct 12, 2026TGX-Android/Telegram-X/main • 012c76b • 2 files, +3/-3 Always use `c++_shared` now TGX-And…
  6. Oct 11, 2026morethanwords/tweb/master • 94bbdf4 • 2 files, +98/-2 Folder tags: leave the rows without…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →