diff --git a/src/Moltbot.Tray.WinUI/App.xaml.cs b/src/Moltbot.Tray.WinUI/App.xaml.cs index 02082e6..d974fb7 100644 --- a/src/Moltbot.Tray.WinUI/App.xaml.cs +++ b/src/Moltbot.Tray.WinUI/App.xaml.cs @@ -157,7 +157,7 @@ public partial class App : Application // Don't set e.Flyout - we're handling it ourselves } - private void ShowTrayMenuPopup() + private async void ShowTrayMenuPopup() { // Close any existing menu if (_trayMenuWindow != null) @@ -166,6 +166,19 @@ public partial class App : Application _trayMenuWindow = null; } + // Pre-fetch latest data before showing menu + if (_gatewayClient != null && _currentStatus == ConnectionStatus.Connected) + { + try + { + _ = _gatewayClient.CheckHealthAsync(); + _ = _gatewayClient.RequestSessionsAsync(); + _ = _gatewayClient.RequestUsageAsync(); + await Task.Delay(150); // Brief wait for data + } + catch { /* ignore - show cached data */ } + } + _trayMenuWindow = new TrayMenuWindow(); _trayMenuWindow.MenuItemClicked += OnTrayMenuItemClicked; _trayMenuWindow.Closed += (s, e) => _trayMenuWindow = null; @@ -226,7 +239,7 @@ public partial class App : Application menu.AddMenuItem(_lastUsage.DisplayText, "๐Ÿ“Š", "", isEnabled: false); } - // Sessions + // Sessions (if any) - show meaningful info like the WinForms version if (_lastSessions.Length > 0) { menu.AddSeparator(); @@ -234,11 +247,31 @@ public partial class App : Application foreach (var session in _lastSessions.Take(5)) { - menu.AddMenuItem($" {session.DisplayText}", null, $"session:{session.Key}"); + // Extract session type from key like "agent:main:cron:uuid" or "agent:main:subagent:uuid" + var parts = session.Key.Split(':'); + var sessionType = parts.Length >= 3 ? parts[2] : "session"; + var displayName = sessionType switch + { + "main" => "Main Agent", + "cron" => "Scheduled Task", + "subagent" => "Sub-Agent", + _ => sessionType.Length > 0 ? char.ToUpper(sessionType[0]) + sessionType[1..] : "Session" + }; + + // Add model if available + if (!string.IsNullOrEmpty(session.Model)) + displayName += $" ({session.Model})"; + else if (!string.IsNullOrEmpty(session.Channel)) + displayName += $" ยท {session.Channel}"; + + var icon = session.IsMain ? "โญ" : "โ€ข"; + menu.AddMenuItem(displayName, icon, $"session:{session.Key}", isEnabled: false, indent: true); } + if (_lastSessions.Length > 5) + menu.AddMenuItem($"+{_lastSessions.Length - 5} more...", "", "", isEnabled: false, indent: true); } - // Channels + // Channels (if any) if (_lastChannels.Length > 0) { menu.AddSeparator(); @@ -246,13 +279,19 @@ public partial class App : Application foreach (var channel in _lastChannels) { - var channelIcon = channel.Status?.ToLowerInvariant() switch + var rawStatus = channel.Status?.ToLowerInvariant() ?? ""; + + // Match status logic from WinForms version + var channelIcon = rawStatus switch { - "ok" or "connected" or "running" => "๐ŸŸข", - "connecting" or "reconnecting" => "๐ŸŸก", - _ => "๐Ÿ”ด" + "ok" or "connected" or "running" or "active" or "ready" => "๐ŸŸข", + "stopped" or "idle" or "paused" or "configured" or "pending" => "๐ŸŸก", + "error" or "disconnected" or "failed" => "๐Ÿ”ด", + _ => "โšช" }; - menu.AddMenuItem(channel.Name, channelIcon, $"channel:{channel.Name}", indent: true); + + var channelName = char.ToUpper(channel.Name[0]) + channel.Name[1..]; + menu.AddMenuItem(channelName, channelIcon, $"channel:{channel.Name}", indent: true); } }