2026-11-02 04:13:58 +00:00
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace UCVL.VPNPlus;
|
|
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
private readonly BadgeLabel _identityBadge = new();
|
|
|
|
|
private readonly BadgeLabel _scheduleBadge = new();
|
|
|
|
|
private readonly Label _sampleLabel = new();
|
|
|
|
|
private readonly Label _uploadLegend = new();
|
|
|
|
|
private readonly Label _downloadLegend = new();
|
|
|
|
|
private readonly Label _historyStatus = new();
|
|
|
|
|
private readonly ReadOnlyModeLabel _routeReadOnly = new();
|
2026-11-03 15:15:23 +00:00
|
|
|
private readonly DashboardCombo _historyRangeCombo = new();
|
|
|
|
|
private readonly Label _selectionHeading = new(), _actualModeHeading = new();
|
2026-11-02 04:13:58 +00:00
|
|
|
private readonly Label _footerHint = new();
|
|
|
|
|
private readonly Label _footerPoem = new();
|
|
|
|
|
private readonly PictureBox _footerCompanyLogo = new();
|
|
|
|
|
private readonly Label _footerCompanySite = new();
|
|
|
|
|
private readonly CardPanel _nodeCard = new(), _modeCard = new(), _trafficCard = new(), _dailyCard = new();
|
|
|
|
|
private readonly ScenicPanel _footer = new() { FooterArtwork = true };
|
|
|
|
|
private readonly ScenicPanel _dashboardBody = new();
|
|
|
|
|
private readonly VScrollBar _dashboardScrollBar = new();
|
|
|
|
|
private readonly MetricCard _usageMetric = new("本期代理流量", DashboardIcon.Database);
|
|
|
|
|
private readonly MetricCard _uploadMetric = new("上传速度", DashboardIcon.Upload);
|
|
|
|
|
private readonly MetricCard _downloadMetric = new("下载速度", DashboardIcon.Download);
|
|
|
|
|
private readonly MetricCard _sessionMetric = new("本次代理流量", DashboardIcon.Document);
|
|
|
|
|
private readonly DashboardGlyph _nodeIcon = new(DashboardIcon.Server), _modeIcon = new(DashboardIcon.Settings);
|
|
|
|
|
private readonly DashboardGlyph _trafficIcon = new(DashboardIcon.Chart), _dailyIcon = new(DashboardIcon.History);
|
|
|
|
|
private readonly Label _trafficHeading = new(), _dailyHeading = new(), _trendHeading = new();
|
|
|
|
|
private readonly CardPanel _speedTrendCard = new();
|
|
|
|
|
private bool _layingOutDashboard;
|
|
|
|
|
private sealed record SpeedHistoryPeriod(int Minutes, string Label)
|
|
|
|
|
{
|
|
|
|
|
public override string ToString() => Label;
|
|
|
|
|
internal static readonly SpeedHistoryPeriod[] All = [new(1, "近 1 分钟"), new(5, "近 5 分钟"), new(15, "近 15 分钟"), new(60, "近 1 小时")];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BuildDashboardView()
|
|
|
|
|
{
|
|
|
|
|
_dashboardView.Dock = DockStyle.Fill;
|
|
|
|
|
_dashboardView.BackColor = Brand.Surface;
|
|
|
|
|
_dashboardView.LoginArtwork = true;
|
|
|
|
|
_dashboardView.AutoScroll = false;
|
|
|
|
|
_dashboardView.Visible = false;
|
|
|
|
|
_dashboardView.Resize += (_, _) => LayoutDashboard();
|
|
|
|
|
_content.Controls.Add(_dashboardView);
|
|
|
|
|
_dashboardBody.BackColor = Brand.Surface;
|
|
|
|
|
_dashboardBody.ParentArtwork = true;
|
|
|
|
|
_dashboardView.Controls.Add(_dashboardBody);
|
|
|
|
|
_dashboardView.Controls.Add(_dashboardScrollBar);
|
|
|
|
|
_dashboardScrollBar.AccessibleName = "主界面垂直滚动";
|
|
|
|
|
_dashboardScrollBar.ValueChanged += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
_dashboardBody.Top = -_dashboardScrollBar.Value;
|
|
|
|
|
// Child surfaces use the viewport's fixed backdrop coordinates.
|
|
|
|
|
// Moving a canvas must repaint them, not bit-blit old transparent pixels.
|
|
|
|
|
_dashboardBody.Invalidate(true);
|
|
|
|
|
};
|
2026-11-03 15:15:23 +00:00
|
|
|
ConfigureLabel(_welcomeLabel, "", Brand.Font(11, FontStyle.Bold), Brand.Navy);
|
2026-11-02 04:13:58 +00:00
|
|
|
ConfigureLabel(_accountLabel, "", Brand.Font(9.5f), Brand.Muted);
|
|
|
|
|
ConfigureLabel(_identityBadge, "", Brand.Font(8.5f), Brand.RoyalBlue);
|
|
|
|
|
ConfigureLabel(_scheduleBadge, "AI 自动调度", Brand.Font(8, FontStyle.Bold), Brand.RoyalBlue);
|
|
|
|
|
foreach (var badge in new[] { _identityBadge, _scheduleBadge })
|
|
|
|
|
{
|
|
|
|
|
badge.BackColor = Color.FromArgb(226, 239, 255);
|
|
|
|
|
badge.TextAlign = ContentAlignment.MiddleCenter;
|
|
|
|
|
}
|
|
|
|
|
ConfigureSecondaryButton(_logoutButton, "退出账号", Point.Empty, new(104, 34));
|
|
|
|
|
_logoutButton.ForeColor = Brand.RoyalBlue;
|
|
|
|
|
_logoutButton.Click += async (_, _) => await LogoutAsync();
|
|
|
|
|
_dashboardBody.Controls.AddRange([_welcomeLabel, _accountLabel, _identityBadge, _logoutButton]);
|
|
|
|
|
|
|
|
|
|
ConfigureLabel(_statusTitle, "未连接", Brand.Font(17, FontStyle.Bold), Brand.Text);
|
|
|
|
|
ConfigureLabel(_statusDetail, "点击连接,自动选择工作节点", Brand.Font(9.5f), Brand.Muted);
|
|
|
|
|
_statusDot.ForeColor = Brand.Muted;
|
|
|
|
|
_statusCard.ScenicStatus = true;
|
2026-11-03 15:15:23 +00:00
|
|
|
_nodeCard.AccentBar = _modeCard.AccentBar = false;
|
|
|
|
|
_modeCard.Embedded = true;
|
2026-11-02 04:13:58 +00:00
|
|
|
_trafficCard.MetricBand = _dailyCard.MetricBand = false;
|
|
|
|
|
ConfigurePrimaryButton(_connectButton, "连接", Point.Empty, new(130, 42));
|
|
|
|
|
_connectButton.Click += async (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
if (!_busy && !_wantConnected && !_handoverOperating)
|
|
|
|
|
_tailnetPreference.ResetForUserConnect();
|
|
|
|
|
await ToggleConnectionAsync();
|
|
|
|
|
};
|
|
|
|
|
_statusCard.Controls.AddRange([_statusDot, _statusTitle, _statusDetail, _connectButton]);
|
|
|
|
|
ConfigureLabel(_nodeHeading, "当前工作节点", Brand.Font(9), Brand.Text);
|
|
|
|
|
ConfigureLabel(_routeHeading, "代理模式", Brand.Font(9), Brand.Text);
|
2026-11-03 15:15:23 +00:00
|
|
|
ConfigureLabel(_currentNodeLabel, "未连接", Brand.Font(9.5f, FontStyle.Bold), Brand.RoyalBlue);
|
|
|
|
|
ConfigureLabel(_selectionHeading, "调度", Brand.Font(7.5f), Brand.Muted);
|
|
|
|
|
ConfigureLabel(_actualModeHeading, "模式", Brand.Font(7.5f), Brand.Muted);
|
|
|
|
|
_modeCard.Controls.AddRange([_nodeHeading, _currentNodeLabel, _actualModeHeading, _routeReadOnly]);
|
|
|
|
|
_nodeCard.Controls.AddRange([_selectionHeading, _routeHeading, _modeCard]);
|
|
|
|
|
_modeCard.Paint += (_, e) =>
|
|
|
|
|
{
|
|
|
|
|
using var divider = new Pen(Color.FromArgb(130, 160, 189, 211), Math.Max(1, DeviceDpi / 96f * .6f));
|
|
|
|
|
e.Graphics.DrawLine(divider, 0, ScaleLogical(4), 0, _modeCard.Height - ScaleLogical(4));
|
|
|
|
|
};
|
2026-11-02 04:13:58 +00:00
|
|
|
BuildConnectionSelection();
|
|
|
|
|
ConfigureCombo(_routeCombo, Point.Empty, new(220, 30));
|
2026-11-03 15:15:23 +00:00
|
|
|
_routeCombo.BackColor = Color.Transparent;
|
2026-11-02 04:13:58 +00:00
|
|
|
_routeCombo.AccessibleName = "代理模式(连接时不可更改)";
|
2026-11-03 15:15:23 +00:00
|
|
|
_routeReadOnly.Visible = true;
|
|
|
|
|
_routeReadOnly.ForeColor = Brand.DeepBlue;
|
|
|
|
|
_nodeCard.Controls.Add(_routeCombo);
|
2026-11-02 04:13:58 +00:00
|
|
|
|
2026-11-03 15:15:23 +00:00
|
|
|
ConfigureLabel(_trafficHeading, "代理实时速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
|
|
|
|
_trafficCard.AccessibleDescription = "纵横家当前全部代理速度,包含当前 Tailscale 传输;非整机流量。";
|
2026-11-02 04:13:58 +00:00
|
|
|
ConfigureLabel(_dailyHeading, "累计流量", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
|
|
|
|
ConfigureLabel(_sampleLabel, "仅代理流量 · 近 5 分钟", Brand.Font(7.5f), Brand.Muted);
|
|
|
|
|
_sampleLabel.TextAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
ConfigureLabel(_uploadLegend, "● 上传 —", Brand.Font(8), Brand.RoyalBlue);
|
|
|
|
|
ConfigureLabel(_downloadLegend, "● 下载 —", Brand.Font(8), Brand.Cyan);
|
2026-11-03 15:15:23 +00:00
|
|
|
ConfigureLabel(_historyStatus, "仅本次运行采样 · KB/s 起", Brand.Font(7), Brand.Muted);
|
2026-11-02 04:13:58 +00:00
|
|
|
_historyStatus.AutoEllipsis = true;
|
|
|
|
|
_historyStatus.TextAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
_historyStatus.AccessibleDescription = "代理速度曲线仅为当前客户端实际采集的代理速度;右侧累计区只显示统计数字。";
|
|
|
|
|
ConfigureLabel(_trendHeading, "代理速度趋势", Brand.Font(8, FontStyle.Bold), Brand.Text);
|
|
|
|
|
_trafficCard.Controls.AddRange([_trafficIcon, _trafficHeading]);
|
|
|
|
|
_dailyCard.Controls.AddRange([_dailyIcon, _dailyHeading]);
|
|
|
|
|
_speedTrendCard.Controls.AddRange([_trendHeading, _trafficChart, _uploadLegend, _downloadLegend]);
|
|
|
|
|
// Keep backend accounting data available to UpdateProfile, but daily
|
|
|
|
|
// byte totals are no longer drawn as a misleading speed history.
|
|
|
|
|
_dailyChart.Visible = false;
|
|
|
|
|
ConfigureCombo(_historyRangeCombo, Point.Empty, new(120, 28));
|
2026-11-03 15:15:23 +00:00
|
|
|
_historyRangeCombo.BackColor = Color.Transparent;
|
2026-11-02 04:13:58 +00:00
|
|
|
_historyRangeCombo.Font = Brand.Font(8.5f);
|
|
|
|
|
_historyRangeCombo.AccessibleName = "代理实时速度时间范围";
|
|
|
|
|
_historyRangeCombo.Items.AddRange(SpeedHistoryPeriod.All);
|
|
|
|
|
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[1];
|
|
|
|
|
_historyRangeCombo.SelectedIndexChanged += (_, _) =>
|
|
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
if (_historyRangeCombo.SelectedItem is SpeedHistoryPeriod period)
|
|
|
|
|
{
|
|
|
|
|
_trafficChart.SetPeriodMinutes(period.Minutes);
|
|
|
|
|
_nodeTrafficPanel.SetPeriodMinutes(period.Minutes);
|
|
|
|
|
}
|
2026-11-02 04:13:58 +00:00
|
|
|
};
|
|
|
|
|
_speedTrendCard.Controls.AddRange([_historyRangeCombo, _historyStatus]);
|
|
|
|
|
ConfigureLabel(_planLabel, "", Brand.Font(8.5f), Brand.Muted);
|
|
|
|
|
ConfigureLabel(_expiryLabel, "", Brand.Font(8.5f), Brand.Muted);
|
|
|
|
|
ConfigureLabel(_footerHint, "仅限内部使用,不作商业使用。", Brand.Font(9, FontStyle.Bold), Brand.DeepBlue);
|
|
|
|
|
_footerHint.TextAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
ConfigureLabel(_footerPoem, "— 科技守护连接 · 让世界更近 —", new Font("KaiTi", 11.5f), Brand.Muted);
|
|
|
|
|
_footerPoem.TextAlign = ContentAlignment.MiddleRight;
|
|
|
|
|
_footerCompanyLogo.Image = LoadCompanyLogo();
|
|
|
|
|
_footerCompanyLogo.SizeMode = PictureBoxSizeMode.Zoom;
|
|
|
|
|
ConfigureLabel(_footerCompanySite, "vpn.example.invalid", Brand.Font(8), Brand.Muted);
|
|
|
|
|
_footerCompanyLogo.BackColor = Color.Transparent;
|
|
|
|
|
_footer.Controls.AddRange([_planLabel, _expiryLabel, _footerHint, _footerPoem, _footerCompanyLogo, _footerCompanySite]);
|
2026-11-03 15:15:23 +00:00
|
|
|
foreach (var card in new CardPanel[] { _statusCard, _nodeCard, _trafficCard, _speedTrendCard, _dailyCard })
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
|
|
|
|
card.BackColor = Color.White;
|
|
|
|
|
_dashboardBody.Controls.Add(card);
|
|
|
|
|
}
|
|
|
|
|
foreach (var metric in new[] { _usageMetric, _sessionMetric, _uploadMetric, _downloadMetric }) metric.Embedded = true;
|
|
|
|
|
_trafficCard.Controls.AddRange([_uploadMetric, _downloadMetric]);
|
|
|
|
|
_dailyCard.Controls.AddRange([_usageMetric, _sessionMetric]);
|
|
|
|
|
BuildTailnetTrafficCard();
|
|
|
|
|
BuildNodeTrafficMonitor();
|
|
|
|
|
_dashboardBody.Controls.Add(_footer);
|
|
|
|
|
foreach (var label in new[] { _welcomeLabel, _accountLabel, _statusTitle, _statusDetail, _currentNodeLabel, _planLabel, _expiryLabel })
|
|
|
|
|
{
|
|
|
|
|
label.AutoEllipsis = true;
|
|
|
|
|
label.TextAlign = ContentAlignment.MiddleLeft;
|
|
|
|
|
}
|
|
|
|
|
_sessionMetric.SetBytes(0, hint: "本次连接累计");
|
|
|
|
|
DisplayTraffic(null, null, "仅代理流量 · 近 5 分钟");
|
|
|
|
|
// The dashboard is one fitted page; no hidden vertical or horizontal
|
|
|
|
|
// canvas is introduced by Tailnet, and mouse-wheel cannot shift it.
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisplayTraffic(double? upload, double? download, string sampling)
|
|
|
|
|
{
|
2026-11-03 15:15:23 +00:00
|
|
|
_uploadMetric.SetBytes(upload, speed: true, hint: "代理总速度");
|
|
|
|
|
_downloadMetric.SetBytes(download, speed: true, hint: "代理总速度");
|
2026-11-02 04:13:58 +00:00
|
|
|
_sampleLabel.Text = sampling;
|
2026-11-03 15:15:23 +00:00
|
|
|
_uploadLegend.Text = "● 上传 " + SpeedDisplay.Format(upload);
|
|
|
|
|
_downloadLegend.Text = "● 下载 " + SpeedDisplay.Format(download);
|
2026-11-02 04:13:58 +00:00
|
|
|
// Waiting/handover/error paths also invalidate the separate transport
|
|
|
|
|
// view. Valid samples are supplied once by the existing traffic reader.
|
|
|
|
|
if (!upload.HasValue || !download.HasValue) DisplayTailnetTraffic(null, null, sampling);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LayoutDashboard()
|
|
|
|
|
{
|
|
|
|
|
if (_layingOutDashboard || _dashboardView.ClientSize.Width <= 0) return;
|
|
|
|
|
_layingOutDashboard = true;
|
|
|
|
|
Control[] layoutContainers = [_dashboardView, _dashboardBody, _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _nodeTrafficPanel, _footer];
|
|
|
|
|
foreach (var container in layoutContainers) container.SuspendLayout();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ApplyCompactTypography();
|
|
|
|
|
var viewport = _dashboardView.ClientSize;
|
|
|
|
|
var layout = DashboardLayout.Calculate(viewport, DeviceDpi, _tailnetTrafficVisible, _canViewNodeTraffic, CompactPresentation);
|
|
|
|
|
var titleSize = CompactPresentation ? 10f : 17f * Math.Max(.7f, layout.VerticalScale);
|
|
|
|
|
SetStatusTitleFont(titleSize);
|
|
|
|
|
_dashboardScrollBar.Visible = false;
|
|
|
|
|
_dashboardScrollBar.Value = 0;
|
|
|
|
|
_dashboardScrollBar.Maximum = 0;
|
|
|
|
|
void Place(Control c, Rectangle r) { c.Bounds = r; }
|
|
|
|
|
Place(_welcomeLabel, layout.WelcomeLabel); Place(_accountLabel, layout.AccountLabel);
|
|
|
|
|
Place(_identityBadge, layout.IdentityBadge); Place(_logoutButton, layout.LogoutButton);
|
|
|
|
|
Place(_statusCard, layout.StatusCard); Place(_nodeCard, layout.NodeCard); Place(_modeCard, layout.ModeCard);
|
|
|
|
|
var metrics = new[] { _usageMetric, _uploadMetric, _downloadMetric, _sessionMetric };
|
|
|
|
|
for (var i = 0; i < 4; i++) Place(metrics[i], layout.Metrics[i]);
|
|
|
|
|
Place(_trafficCard, layout.TrafficCard); Place(_speedTrendCard, layout.SpeedTrendCard); Place(_dailyCard, layout.DailyCard); Place(_footer, layout.Footer);
|
|
|
|
|
Place(_nodeTrafficPanel, layout.ServerTrafficCard);
|
2026-11-03 15:15:23 +00:00
|
|
|
_tailnetTrafficCard.Bounds=layout.TailnetTrafficCard;
|
2026-11-06 10:54:33 +00:00
|
|
|
_trafficCard.Visible=_tailnetTrafficCard.Visible=false;
|
2026-11-03 15:15:23 +00:00
|
|
|
_tailnetSampleLabel.Visible=false;
|
|
|
|
|
LayoutCompactDashboard(layout);
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
foreach (var container in layoutContainers.Reverse()) container.ResumeLayout(false);
|
|
|
|
|
_layingOutDashboard = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-06 10:54:33 +00:00
|
|
|
// Isolated synthetic presentation fixture; it never starts a proxy or reads credentials.
|
2026-11-02 04:13:58 +00:00
|
|
|
internal static void RenderPreview()
|
|
|
|
|
{
|
|
|
|
|
using var form = new MainForm(preview: true) { Opacity = 0, ShowInTaskbar = false };
|
|
|
|
|
form.Show();
|
|
|
|
|
form.ShowDashboard(new Profile
|
|
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
DisplayName="示例用户",Email="demo@example.com",IdentityType="employee",
|
|
|
|
|
Subscription=new SubscriptionInfo {Plan="员工福利",UsedBytes=276L*1024*1024*1024,DeviceLimit=10},
|
|
|
|
|
Nodes=[new NodeInfo {Name="VPN002",Slug="aliyun-tokyo-002",Status="online"}],
|
|
|
|
|
RouteModes=[new RouteModeInfo {Id="smart",Name="AI 智能代理"}]
|
2026-11-02 04:13:58 +00:00
|
|
|
});
|
|
|
|
|
form._refreshTimer.Stop();
|
2026-11-06 10:54:33 +00:00
|
|
|
form.ClientSize=new Size(form.ScaleLogical(480),form.ScaleLogical(360));
|
|
|
|
|
form._currentNodeBaseName="VPN002";
|
|
|
|
|
form.UpdateConnectedTransportPresentation(true);
|
|
|
|
|
form.SetConnectionState(true,"已安全连接","VPN002 + Tailscale · AI 智能代理");
|
|
|
|
|
form.DisplayTraffic(1_153_433,64_614,"演示样本 · 近 5 分钟");
|
|
|
|
|
form._sessionMetric.SetBytes(1_883_750_912,hint:"本次连接累计");
|
|
|
|
|
var now=DateTimeOffset.UtcNow;
|
|
|
|
|
var serverClock=now;
|
|
|
|
|
using var previewServers=new NodeTrafficPanel(()=>serverClock) {Visible=false};
|
|
|
|
|
form._dashboardBody.Controls.Add(previewServers);
|
|
|
|
|
var showServerFixture=false;
|
|
|
|
|
for(var i=0;i<61;i++) form._trafficChart.Add((1500+Math.Sin(i*.8)*500)*1024,
|
|
|
|
|
(i%9==0?1900:80+Math.Sin(i*.4)*35)*1024,now.AddSeconds((i-60)*5));
|
|
|
|
|
form.DisplayTraffic((1500+Math.Sin(60*.8)*500)*1024,(80+Math.Sin(60*.4)*35)*1024,"演示样本 · 近 5 分钟");
|
|
|
|
|
form.LayoutDashboard();
|
|
|
|
|
var checks=new Dictionary<string,bool>
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
["geometry_all_viewport_and_dpi_cases"]=DashboardLayout.SelfTest(),
|
|
|
|
|
["fixed_half_size_window"]=form.ClientSize==new Size(form.ScaleLogical(480),form.ScaleLogical(360)),
|
|
|
|
|
["repeated_proxy_and_tailnet_rows_hidden"]=!form._trafficCard.Visible&&!form._tailnetTrafficCard.Visible,
|
|
|
|
|
["local_graph_caption_identifies_tailnet"]=form._trendHeading.Text.Contains("Tailscale"),
|
|
|
|
|
["local_graph_has_actual_upload_download_values"]=form._uploadLegend.Visible&&form._downloadLegend.Visible
|
|
|
|
|
&&form._uploadLegend.Text.Contains("MB/s")&&form._downloadLegend.Text.Contains("KB/s"),
|
|
|
|
|
["totals_numeric_only"]=!form._dailyCard.Controls.OfType<TrafficChart>().Any(),
|
|
|
|
|
["configuration_actual_state_aligned"]=form._connectionModeCombo.PointToScreen(Point.Empty).Y==form._currentNodeLabel.PointToScreen(Point.Empty).Y,
|
|
|
|
|
["no_dashboard_scroll"]=!form._dashboardScrollBar.Visible&&form._dashboardBody.Location==Point.Empty,
|
|
|
|
|
["controls_fit"]=form.DashboardControlsFit(),
|
|
|
|
|
["half_transparent_surfaces"]=CardPanel.SurfaceAlpha==128
|
|
|
|
|
};
|
2026-11-02 04:13:58 +00:00
|
|
|
void Capture(string suffix)
|
|
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
form.PerformLayout();form.LayoutDashboard();Application.DoEvents();
|
|
|
|
|
if(showServerFixture)
|
|
|
|
|
{
|
|
|
|
|
previewServers.Bounds=form._nodeTrafficPanel.Bounds;
|
|
|
|
|
previewServers.Visible=form._canViewNodeTraffic;
|
|
|
|
|
form._nodeTrafficPanel.Visible=false;
|
|
|
|
|
previewServers.BringToFront();
|
|
|
|
|
}
|
|
|
|
|
using var image=new Bitmap(form.Width,form.Height);
|
|
|
|
|
form.DrawToBitmap(image,new Rectangle(Point.Empty,image.Size));
|
|
|
|
|
image.Save(Path.Combine(AppContext.BaseDirectory,$"preview-{GetDisplayVersion()}-{form.DeviceDpi}dpi-{suffix}.png"));
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
2026-11-06 10:54:33 +00:00
|
|
|
Capture("local-trend-tailnet");
|
|
|
|
|
var originalBounds=(form._speedTrendCard.Bounds,form._dailyCard.Bounds,form._footer.Bounds);
|
|
|
|
|
form.UpdateConnectedTransportPresentation(false);
|
|
|
|
|
checks["domain_caption_changes_without_resizing"]=form._trendHeading.Text.Contains("域名入口")
|
|
|
|
|
&&originalBounds==(form._speedTrendCard.Bounds,form._dailyCard.Bounds,form._footer.Bounds);
|
|
|
|
|
Capture("local-trend-domain");
|
|
|
|
|
form.UpdateConnectedTransportPresentation(true);
|
|
|
|
|
form.SetNodeTrafficPermission(true);
|
|
|
|
|
showServerFixture=true;
|
|
|
|
|
NodeTrafficSnapshot? lastServerFixture=null;
|
|
|
|
|
for(var i=0;i<301;i++)
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
var sampled=now.AddSeconds(i-300);
|
|
|
|
|
serverClock=sampled;
|
|
|
|
|
lastServerFixture=new NodeTrafficSnapshot
|
|
|
|
|
{
|
|
|
|
|
Contract=1,Scope="server_host_interface",Source="linux_host_interface",Direction="interface_perspective",
|
|
|
|
|
CounterSince="boot_or_interface_reset",SamplePeriodSeconds=1,GeneratedAt=sampled,
|
|
|
|
|
Nodes=new[]{("VPN002 东京","aliyun-tokyo-002"),("VPN003 美国","aliyun-siliconvalley-003"),
|
|
|
|
|
("济南 博翠明湖","jinan-phone"),("VPN004 纽约","racknerd-newyork-004")}.Select((node,index)=>new NodeTrafficReading
|
|
|
|
|
{
|
|
|
|
|
Name=node.Item1,Slug=node.Item2,SampledAt=sampled,IntervalSeconds=1,CounterEpoch="synthetic-preview",
|
|
|
|
|
UploadRate=(long)((20+(index+1)*12+Math.Sin(i*.035+index)*15)*1024),
|
|
|
|
|
DownloadRate=(long)((150+(index+1)*45+Math.Sin(i*.07+index)*120)*1024)
|
|
|
|
|
}).ToList()
|
|
|
|
|
};
|
|
|
|
|
previewServers.SetSnapshot(lastServerFixture);
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
2026-11-06 10:54:33 +00:00
|
|
|
form.LayoutDashboard();Capture("local-and-four-server-trends");
|
|
|
|
|
checks["four_server_rows_received"]=previewServers.ServerCount==4;
|
|
|
|
|
checks["graphs_order_local_then_servers_then_totals"]=form._speedTrendCard.Bottom<form._nodeTrafficPanel.Top
|
|
|
|
|
&&form._nodeTrafficPanel.Bottom<form._dailyCard.Top&&form._dailyCard.Bottom<form._footer.Top;
|
|
|
|
|
checks["four_servers_have_distinct_samples"]=previewServers.History("racknerd-newyork-004").Last().Up
|
|
|
|
|
!=previewServers.History("aliyun-tokyo-002").Last().Up;
|
|
|
|
|
checks["no_personal_accounting_changes_from_server_samples"]=form._sessionUp==0&&form._sessionDown==0;
|
|
|
|
|
checks["server_graphs_keep_window_and_controls_fitted"]=form.DashboardControlsFit()&&!form._dashboardScrollBar.Visible;
|
|
|
|
|
foreach(var period in SpeedHistoryPeriod.All)
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
form._historyRangeCombo.SelectedItem=period;
|
|
|
|
|
previewServers.SetPeriodMinutes(period.Minutes);
|
|
|
|
|
checks["local_and_server_range_"+period.Minutes]=form._trafficChart.PeriodMinutes==period.Minutes
|
|
|
|
|
&&previewServers.HistoryCount("racknerd-newyork-004")==301;
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
2026-11-06 10:54:33 +00:00
|
|
|
form._historyRangeCombo.SelectedItem=SpeedHistoryPeriod.All[1];
|
|
|
|
|
previewServers.SetPeriodMinutes(5);
|
|
|
|
|
previewServers.SetSnapshot(new NodeTrafficSnapshot
|
2026-11-03 15:15:23 +00:00
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
Contract=1,Scope="server_host_interface",Source="linux_host_interface",Direction="interface_perspective",
|
|
|
|
|
CounterSince="boot_or_interface_reset",SamplePeriodSeconds=1,GeneratedAt=now,
|
|
|
|
|
Nodes=lastServerFixture!.Nodes.Where(row=>row.Slug!="jinan-phone").ToList()
|
2026-11-03 15:15:23 +00:00
|
|
|
});
|
2026-11-06 10:54:33 +00:00
|
|
|
Capture("local-and-three-server-trends");
|
|
|
|
|
checks["three_live_server_fixture_fits_without_height_change"]=previewServers.ServerCount==3
|
|
|
|
|
&&form.DashboardControlsFit()&&!form._dashboardScrollBar.Visible;
|
|
|
|
|
previewServers.Unavailable("后台尚未提供服务器监控",clear:true);
|
|
|
|
|
Capture("server-monitor-unavailable");
|
|
|
|
|
checks["missing_server_data_does_not_invent_rows"]=previewServers.ServerCount==0;
|
2026-11-02 04:13:58 +00:00
|
|
|
form.SetNodeTrafficPermission(false);
|
2026-11-06 10:54:33 +00:00
|
|
|
form.SetConnectionState(false,"未连接","连接后显示代理速度趋势");
|
|
|
|
|
form._trafficChart.Reset();Capture("disconnected");
|
|
|
|
|
checks["disconnected_values_not_stale"]=form._uploadLegend.Text.Contains("—")&&form._downloadLegend.Text.Contains("—");
|
|
|
|
|
form.ShowLogin();Capture("login");
|
|
|
|
|
checks["login_still_fits"]=form.LoginFieldsVisibleForTest&&form.LoginRegistrationAlignedForTest;
|
|
|
|
|
File.WriteAllText(Path.Combine(AppContext.BaseDirectory,"dashboard-ui-self-test.json"),JsonSerializer.Serialize(new
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
2026-11-06 10:54:33 +00:00
|
|
|
version=GetDisplayVersion(),passed=checks.Values.All(value=>value),checks,dpi=form.DeviceDpi,
|
|
|
|
|
synthetic_data=true,network_modified=false,installed_client_modified=false,production_sample_observed=false
|
|
|
|
|
},new JsonSerializerOptions {WriteIndented=true}));
|
2026-11-02 04:13:58 +00:00
|
|
|
form.RequestExit();
|
2026-11-06 10:54:33 +00:00
|
|
|
if(checks.Values.Any(value=>!value))throw new InvalidOperationException("Dashboard UI self-test failed; inspect dashboard-ui-self-test.json");
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool DashboardControlsFit() => new Control[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _footer }
|
|
|
|
|
.Where(parent => parent.Visible)
|
|
|
|
|
.All(parent => parent.Controls.Cast<Control>().Where(c => c.Visible).All(c => c.Left >= 0 && c.Top >= 0 && c.Right <= parent.ClientSize.Width && c.Bottom <= parent.ClientSize.Height));
|
|
|
|
|
}
|