| 1 | using Microsoft.UI.Xaml; |
| 2 | using Microsoft.UI.Xaml.Controls; |
| 3 | using RblxTool.Interop; |
| 4 | using RblxTool.Services; |
| 5 | |
| 6 | namespace RblxTool.Views; |
| 7 | |
| 8 | public sealed partial class DashboardPage : Page |
| 9 | { |
| 10 | private DispatcherTimer? _timer; |
| 11 | |
| 12 | public DashboardPage() |
| 13 | { |
| 14 | InitializeComponent(); |
| 15 | Loaded += OnLoaded; |
| 16 | Unloaded += (_, _) => _timer?.Stop(); |
| 17 | } |
| 18 | |
| 19 | private void OnLoaded(object sender, RoutedEventArgs e) |
| 20 | { |
| 21 | VersionText.Text = $"rblxtool core {RblxEngine.Version()}"; |
| 22 | _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; |
| 23 | _timer.Tick += (_, _) => RefreshMetrics(); |
| 24 | _timer.Start(); |
| 25 | RefreshMetrics(); |
| 26 | _ = RefreshOverviewAsync(); |
| 27 | } |
| 28 | |
| 29 | private void RefreshMetrics() |
| 30 | { |
| 31 | var metrics = AppState.Current.Engine.Metrics(); |
| 32 | RequestsText.Text = metrics.Requests.ToString("N0"); |
| 33 | LatencyText.Text = $"{metrics.AverageLatencyMs:F0} ms"; |
| 34 | RetriesText.Text = metrics.Retries.ToString("N0"); |
| 35 | ThrottledText.Text = metrics.RateLimited.ToString("N0"); |
| 36 | BytesText.Text = FormatBytes(metrics.BytesIn); |
| 37 | } |
| 38 | |
| 39 | private async Task RefreshOverviewAsync() |
| 40 | { |
| 41 | if (AppState.Current.Active is null) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | var overview = await Task.Run(() => AppState.Current.Engine.Overview()); |
| 46 | if (overview is null) |
| 47 | { |
| 48 | return; |
| 49 | } |
| 50 | RobuxText.Text = overview.Robux.ToString("N0"); |
| 51 | CollectiblesText.Text = overview.Collectibles.ToString("N0"); |
| 52 | RapText.Text = overview.TotalRap.ToString("N0"); |
| 53 | FriendsText.Text = overview.Friends.ToString("N0"); |
| 54 | FollowersText.Text = overview.Followers.ToString("N0"); |
| 55 | } |
| 56 | |
| 57 | private static string FormatBytes(ulong value) |
| 58 | { |
| 59 | double size = value; |
| 60 | string[] units = { "B", "KB", "MB", "GB" }; |
| 61 | var index = 0; |
| 62 | while (size >= 1024 && index < units.Length - 1) |
| 63 | { |
| 64 | size /= 1024; |
| 65 | index++; |
| 66 | } |
| 67 | return $"{size:F1} {units[index]}"; |
| 68 | } |
| 69 | } |