2026-10-13 07:29:03 +00:00
|
|
|
namespace UCVL.VPNPlus;
|
|
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
// Presentation only. These controls never read adapter/counter state and
|
|
|
|
|
// never change proxy, account, session totals or route decisions.
|
2026-10-22 05:43:39 +00:00
|
|
|
private readonly CardPanel _tailnetTrafficCard = new();
|
2026-10-13 07:29:03 +00:00
|
|
|
private readonly MetricCard _tailnetUploadMetric = new("上传速度", DashboardIcon.Upload) { Embedded = true };
|
|
|
|
|
private readonly MetricCard _tailnetDownloadMetric = new("下载速度", DashboardIcon.Download) { Embedded = true };
|
|
|
|
|
private readonly DashboardGlyph _tailnetTrafficIcon = new(DashboardIcon.Chart);
|
|
|
|
|
private readonly Label _tailnetTrafficHeading = new(), _tailnetSampleLabel = new();
|
|
|
|
|
private bool _tailnetTrafficVisible;
|
|
|
|
|
|
|
|
|
|
private void BuildTailnetTrafficCard()
|
|
|
|
|
{
|
2026-10-22 05:43:39 +00:00
|
|
|
ConfigureLabel(_tailnetTrafficHeading, "Tailscale 实时速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
2026-10-13 07:29:03 +00:00
|
|
|
ConfigureLabel(_tailnetSampleLabel, "等待流量采样", Brand.Font(7.5f), Brand.Muted);
|
|
|
|
|
_tailnetSampleLabel.TextAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
_tailnetSampleLabel.AutoEllipsis = true;
|
|
|
|
|
_tailnetTrafficCard.AccessibleName = "Tailscale 实时网速";
|
|
|
|
|
_tailnetTrafficCard.AccessibleDescription = "仅纵横家当前 Tailscale 代理链路;已计入代理总流量,不代表所有 Tailscale 网卡或整机流量。";
|
|
|
|
|
_tailnetTrafficCard.Controls.AddRange([_tailnetTrafficIcon, _tailnetTrafficHeading, _tailnetSampleLabel,
|
2026-10-22 05:43:39 +00:00
|
|
|
_tailnetUploadMetric, _tailnetDownloadMetric]);
|
2026-10-13 07:29:03 +00:00
|
|
|
_tailnetTrafficCard.Visible = false;
|
|
|
|
|
_dashboardBody.Controls.Add(_tailnetTrafficCard);
|
|
|
|
|
ResetTailnetTraffic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void SetTailnetTrafficVisibility(bool show)
|
|
|
|
|
{
|
|
|
|
|
if (_tailnetTrafficVisible == show) return;
|
|
|
|
|
_tailnetTrafficVisible = show;
|
|
|
|
|
_tailnetTrafficCard.Visible = show;
|
|
|
|
|
if (!show) ResetTailnetTraffic();
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void DisplayTailnetTraffic(double? up, double? down, string sampling)
|
|
|
|
|
{
|
|
|
|
|
// Root supplies the already-accounted proxy sample only for the active
|
|
|
|
|
// Tailnet transport. This presentation never reads an adapter or adds
|
|
|
|
|
// bytes to session/backend totals. Missing samples are not fake zeroes.
|
|
|
|
|
static double? Clean(double? value) => value.HasValue && double.IsFinite(value.Value)
|
|
|
|
|
? Math.Max(0, value.Value) : null;
|
|
|
|
|
up = Clean(up); down = Clean(down);
|
|
|
|
|
_tailnetUploadMetric.SetBytes(up, speed: true, hint: "已计入代理总流量");
|
|
|
|
|
_tailnetDownloadMetric.SetBytes(down, speed: true, hint: "已计入代理总流量");
|
|
|
|
|
_tailnetSampleLabel.Text = "仅纵横家链路 · " + sampling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void ResetTailnetTraffic()
|
|
|
|
|
{
|
|
|
|
|
DisplayTailnetTraffic(null, null, "等待 Tailscale 流量采样");
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 05:43:39 +00:00
|
|
|
private void LayoutTailnetTrafficCard(Rectangle bounds, float verticalScale)
|
2026-10-13 07:29:03 +00:00
|
|
|
{
|
|
|
|
|
_tailnetTrafficCard.Visible = _tailnetTrafficVisible;
|
|
|
|
|
if (!_tailnetTrafficVisible) { _tailnetTrafficCard.Bounds = Rectangle.Empty; return; }
|
|
|
|
|
_tailnetTrafficCard.Bounds = bounds;
|
|
|
|
|
int S(int value) => ScaleLogical(value);
|
2026-10-22 05:43:39 +00:00
|
|
|
int Y(int value) => Math.Max(0, (int)Math.Floor(S(value) * verticalScale));
|
|
|
|
|
_tailnetTrafficIcon.Bounds = new Rectangle(S(15), Y(8), S(20), Y(20));
|
|
|
|
|
_tailnetTrafficHeading.Bounds = new Rectangle(S(42), Y(6), Math.Max(1, bounds.Width - S(52)), Y(26));
|
|
|
|
|
// Scope remains accessible, without repeating long disclaimers inside
|
|
|
|
|
// a small speed section. These are the same already-accounted bytes.
|
|
|
|
|
_tailnetSampleLabel.Visible = false;
|
|
|
|
|
var metricWidth = (bounds.Width - S(20)) / 2;
|
|
|
|
|
var metricTop = Math.Max(Y(38), (bounds.Height - Y(82)) / 2);
|
|
|
|
|
var metricHeight = Math.Min(Y(82), bounds.Height - Y(44));
|
|
|
|
|
_tailnetUploadMetric.Bounds = new Rectangle(S(10), metricTop, metricWidth - S(1), metricHeight);
|
|
|
|
|
_tailnetDownloadMetric.Bounds = new Rectangle(S(10) + metricWidth, metricTop, metricWidth - S(1), metricHeight);
|
2026-10-13 07:29:03 +00:00
|
|
|
}
|
|
|
|
|
}
|