TGViewer
Telegram github commits and releases Telegram github commits and releases @tgappsupdates · 4.54K subscribers
Post #20656 77
UnigramDev/Unigram/capture-popup-focus • 8896627 • 1 files, +15/-13
Track focus rather than window activation in ChooseCapturePopup

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 13, 2026UnigramDev/Unigram/develop • 7842fff • 5 files, +1215/-148 Group the rich editor toolbar's…
  2. Oct 13, 2026UnigramDev/Unigram/develop • c04c03a • 2 files, +53/-9 Map spell checking and collapsible…
  3. Oct 13, 2026UnigramDev/Unigram/develop • 5b57a69 • 1 files, +1/-0 Fix event unsubscribe UnigramDev/Uni…
  4. Oct 13, 2026TelegramMessenger/tgcalls/dev/android • 03d7b86 • 1 files, +28/-1 v2: defer camera renegot…
  5. Oct 13, 2026TelegramMessenger/tgcalls/dev/android • 245efc4 • 1 files, +29/-111 Revert "Update Instanc…
  6. Oct 13, 2026DrKLO/Telegram/master • 474c462 • 3 files, +8/-0 update submodules DrKLO/Telegram/master •…
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 →