feat(usage): open the TokenTracker dashboard from the usage monitor
The modal deliberately shows only a slice of the analytics; this hands off to TokenTracker's own local dashboard for the rest. The worker starts `tokentracker serve` on demand and returns the URL, the UI opens the browser. Three things the spawn has to get right: port 7680 is not free on Windows (Delivery Optimization holds [::]:7680) and serve does not fall back, so we scan 7680-7689 with a dual-stack bind probe; --no-open because the CLI would open the browser before the server answers; and the child is a cmd.exe shim, so shutdown kills the process tree. --no-sync keeps our no-cloud-sync rule.
This commit is contained in:
@@ -68,6 +68,8 @@ public sealed partial class UsageMonitorModalViewModel : ViewModelBase
|
||||
[NotifyPropertyChangedFor(nameof(ShowInstallButton))]
|
||||
private bool _isInstalling;
|
||||
|
||||
[ObservableProperty] private bool _isOpeningDashboard;
|
||||
|
||||
public bool ModelsEmpty => !IsBusy && ModelRows.Count == 0;
|
||||
public bool TasksEmpty => !IsBusy && TaskRows.Count == 0;
|
||||
|
||||
@@ -229,6 +231,35 @@ public sealed partial class UsageMonitorModalViewModel : ViewModelBase
|
||||
finally { IsInstalling = false; }
|
||||
}
|
||||
|
||||
/// <summary>Hands off to TokenTracker's own dashboard for everything this modal deliberately
|
||||
/// doesn't show. The worker starts the local server (first start takes a few seconds), we only
|
||||
/// open the browser.</summary>
|
||||
[RelayCommand]
|
||||
private async Task OpenDashboard()
|
||||
{
|
||||
IsOpeningDashboard = true;
|
||||
try
|
||||
{
|
||||
var dashboard = await _worker.OpenTokenTrackerDashboardAsync();
|
||||
if (dashboard is not { Ok: true, Url: { Length: > 0 } url })
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.usageMonitor.dashboardFailed",
|
||||
dashboard?.Error ?? Loc.T("vm.usageMonitor.dashboardUnavailable")));
|
||||
return;
|
||||
}
|
||||
|
||||
var (ok, error) = ShellOpen.Url(url);
|
||||
if (!ok)
|
||||
ErrorReported?.Invoke(Loc.T("vm.usageMonitor.dashboardFailed",
|
||||
error ?? Loc.T("vm.usageMonitor.dashboardUnavailable")));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.usageMonitor.dashboardFailed", ex.Message));
|
||||
}
|
||||
finally { IsOpeningDashboard = false; }
|
||||
}
|
||||
|
||||
private Task SetPreset(int days)
|
||||
{
|
||||
ApplyPresetRange(days);
|
||||
|
||||
Reference in New Issue
Block a user