Fix logo-click crash (Run is not a Visual); Text tab always visible; avatar initial fallback

This commit is contained in:
2026-08-24 14:44:16 -07:00
parent b988e6d72e
commit e6baa55867
7 changed files with 39 additions and 21 deletions
+20 -6
View File
@@ -135,24 +135,35 @@ public partial class MainWindow : Window
private void LoadAvatarImage()
{
if (_viewModel.IsConnected && !string.IsNullOrWhiteSpace(_viewModel.AccountAvatarUrl))
var url = _viewModel.AccountAvatarUrl;
if (_viewModel.IsConnected && !string.IsNullOrWhiteSpace(url))
{
try
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(_viewModel.AccountAvatarUrl, UriKind.Absolute);
bitmap.UriSource = new Uri(url, UriKind.Absolute);
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
AvatarImage.Source = bitmap;
AvatarInitial.Visibility = Visibility.Collapsed;
return;
}
catch (Exception ex)
{
AppLog.Write($"Avatar load failed ({url}): {ex.Message}");
}
catch { AvatarImage.Source = null; }
}
else
else if (_viewModel.IsConnected)
{
AvatarImage.Source = null;
AppLog.Write("Avatar: connected but no profile image URL on the session");
}
AvatarImage.Source = null;
AvatarInitial.Text = string.IsNullOrWhiteSpace(_viewModel.AccountDisplayName)
? "?"
: _viewModel.AccountDisplayName.Substring(0, 1).ToUpperInvariant();
AvatarInitial.Visibility = _viewModel.IsConnected ? Visibility.Visible : Visibility.Collapsed;
}
private void SourceNameBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
@@ -311,7 +322,10 @@ public partial class MainWindow : Window
private static bool IsDescendantOf(DependencyObject? child, DependencyObject ancestor)
{
while (child != null && !ReferenceEquals(child, ancestor))
child = VisualTreeHelper.GetParent(child);
{
var parent = VisualTreeHelper.GetParent(child);
child = parent ?? LogicalTreeHelper.GetParent(child);
}
return child != null;
}