Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -0,0 +1,373 @@
|
||||
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 _dailyUploadLegend = new(), _dailyDownloadLegend = new();
|
||||
private readonly Label _historyStatus = new();
|
||||
private readonly ReadOnlyModeLabel _routeReadOnly = new();
|
||||
private readonly ComboBox _historyRangeCombo = new();
|
||||
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();
|
||||
private bool _layingOutDashboard;
|
||||
|
||||
private void BuildDashboardView()
|
||||
{
|
||||
_dashboardView.Dock = DockStyle.Fill;
|
||||
_dashboardView.BackColor = Brand.Surface;
|
||||
_dashboardView.AutoScroll = false;
|
||||
_dashboardView.Visible = false;
|
||||
_dashboardView.Resize += (_, _) => LayoutDashboard();
|
||||
_content.Controls.Add(_dashboardView);
|
||||
_dashboardBody.BackColor = Brand.Surface;
|
||||
_dashboardView.Controls.Add(_dashboardBody);
|
||||
_dashboardView.Controls.Add(_dashboardScrollBar);
|
||||
_dashboardScrollBar.AccessibleName = "主界面垂直滚动";
|
||||
_dashboardScrollBar.ValueChanged += (_, _) => _dashboardBody.Top = -_dashboardScrollBar.Value;
|
||||
_dashboardView.MouseWheel += DashboardMouseWheel;
|
||||
_dashboardBody.MouseWheel += DashboardMouseWheel;
|
||||
ConfigureLabel(_welcomeLabel, "", Brand.Font(15, FontStyle.Bold), Brand.Navy);
|
||||
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;
|
||||
_nodeCard.AccentBar = _modeCard.AccentBar = true;
|
||||
_trafficCard.MetricBand = _dailyCard.MetricBand = true;
|
||||
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);
|
||||
ConfigureLabel(_currentNodeLabel, "连接后自动分配", Brand.Font(12, FontStyle.Bold), Brand.RoyalBlue);
|
||||
_nodeCard.Controls.AddRange([_nodeIcon, _nodeHeading, _currentNodeLabel, _scheduleBadge]);
|
||||
BuildConnectionSelection();
|
||||
ConfigureCombo(_routeCombo, Point.Empty, new(220, 30));
|
||||
_routeCombo.BackColor = Color.White;
|
||||
_routeCombo.AccessibleName = "代理模式(连接时不可更改)";
|
||||
_routeReadOnly.Visible = false;
|
||||
_modeCard.Controls.AddRange([_modeIcon, _routeHeading, _routeCombo, _routeReadOnly]);
|
||||
|
||||
ConfigureLabel(_trafficHeading, "实时网速", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
||||
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);
|
||||
ConfigureLabel(_dailyUploadLegend, "● 上传", Brand.Font(8), Brand.RoyalBlue);
|
||||
ConfigureLabel(_dailyDownloadLegend, "● 下载", Brand.Font(8), Brand.Cyan);
|
||||
ConfigureLabel(_historyStatus, "套餐全部设备 · 按天统计", Brand.Font(7), Brand.Muted);
|
||||
_historyStatus.AutoEllipsis = true;
|
||||
_historyStatus.TextAlign = ContentAlignment.MiddleRight;
|
||||
_dailyChart.HistoryChanged += () => { _historyStatus.Text = _dailyChart.StatusText; _historyStatus.AccessibleDescription = _dailyChart.DetailText; };
|
||||
_trafficCard.Controls.AddRange([_trafficIcon, _trafficHeading, _sampleLabel, _trafficChart, _uploadLegend, _downloadLegend]);
|
||||
_dailyCard.Controls.AddRange([_dailyIcon, _dailyHeading, _dailyChart, _dailyUploadLegend, _dailyDownloadLegend]);
|
||||
ConfigureCombo(_historyRangeCombo, Point.Empty, new(120, 28));
|
||||
_historyRangeCombo.BackColor = Color.White;
|
||||
_historyRangeCombo.Font = Brand.Font(8.5f);
|
||||
_historyRangeCombo.DrawMode = DrawMode.OwnerDrawFixed;
|
||||
_historyRangeCombo.DrawItem += (_, e) =>
|
||||
{
|
||||
if (e.Index < 0) return;
|
||||
var highlight = _historyRangeCombo.DroppedDown && (e.State & DrawItemState.Selected) != 0;
|
||||
using var fill = new SolidBrush(highlight ? Brand.PaleBlue : Color.White);
|
||||
e.Graphics.FillRectangle(fill, e.Bounds);
|
||||
TextRenderer.DrawText(e.Graphics, _historyRangeCombo.Items[e.Index]?.ToString() ?? "", _historyRangeCombo.Font,
|
||||
e.Bounds, Brand.Text, TextFormatFlags.VerticalCenter | TextFormatFlags.Left | TextFormatFlags.EndEllipsis);
|
||||
e.DrawFocusRectangle();
|
||||
};
|
||||
_historyRangeCombo.AccessibleName = "代理流量历史时间范围";
|
||||
_historyRangeCombo.Items.AddRange(UsageHistoryPeriod.All);
|
||||
_historyRangeCombo.SelectedItem = UsageHistoryPeriod.All[2];
|
||||
_historyRangeCombo.SelectedIndexChanged += (_, _) =>
|
||||
{
|
||||
if (_historyRangeCombo.SelectedItem is UsageHistoryPeriod period) _dailyChart.SetPeriod(period);
|
||||
};
|
||||
_dailyCard.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.toplc.cn", Brand.Font(8), Brand.Muted);
|
||||
_footerCompanyLogo.BackColor = Color.Transparent;
|
||||
_footer.Controls.AddRange([_planLabel, _expiryLabel, _footerHint, _footerPoem, _footerCompanyLogo, _footerCompanySite]);
|
||||
foreach (var card in new CardPanel[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _dailyCard })
|
||||
{
|
||||
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]);
|
||||
_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 分钟");
|
||||
LayoutDashboard();
|
||||
}
|
||||
|
||||
private void DisplayTraffic(double? upload, double? download, string sampling)
|
||||
{
|
||||
_uploadMetric.SetBytes(upload, speed: true);
|
||||
_downloadMetric.SetBytes(download, speed: true);
|
||||
_sampleLabel.Text = sampling;
|
||||
_uploadLegend.Text = upload.HasValue ? $"● 上传 {FormatBytes((long)upload.Value)}/s" : "● 上传 —";
|
||||
_downloadLegend.Text = download.HasValue ? $"● 下载 {FormatBytes((long)download.Value)}/s" : "● 下载 —";
|
||||
}
|
||||
|
||||
private void DashboardMouseWheel(object? sender, MouseEventArgs e)
|
||||
{
|
||||
if (!_dashboardScrollBar.Visible || e is HandledMouseEventArgs { Handled: true }) return;
|
||||
var limit = Math.Max(0, _dashboardScrollBar.Maximum - _dashboardScrollBar.LargeChange + 1);
|
||||
_dashboardScrollBar.Value = Math.Clamp(_dashboardScrollBar.Value - Math.Sign(e.Delta) * ScaleLogical(54), 0, limit);
|
||||
if (e is HandledMouseEventArgs handled) handled.Handled = true;
|
||||
}
|
||||
|
||||
private void LayoutDashboard()
|
||||
{
|
||||
if (_layingOutDashboard || _dashboardView.ClientSize.Width <= 0) return;
|
||||
_layingOutDashboard = true;
|
||||
Control[] layoutContainers = [_dashboardView, _dashboardBody, _statusCard, _nodeCard, _modeCard, _trafficCard, _dailyCard, _footer];
|
||||
foreach (var container in layoutContainers) container.SuspendLayout();
|
||||
try
|
||||
{
|
||||
var previousScroll = _dashboardScrollBar.Value;
|
||||
// Explicit vertical canvas: card reflow must never retain a previous
|
||||
// horizontal extent or reset the user's scroll offset on repaint.
|
||||
var viewport = _dashboardView.ClientSize;
|
||||
var layout = DashboardLayout.Calculate(viewport, DeviceDpi);
|
||||
_dashboardScrollBar.Visible = layout.ContentHeight > viewport.Height;
|
||||
_dashboardScrollBar.Bounds = new Rectangle(viewport.Width - ScaleLogical(17), 0, ScaleLogical(17), viewport.Height);
|
||||
if (_dashboardScrollBar.Visible)
|
||||
layout = DashboardLayout.Calculate(new Size(viewport.Width - ScaleLogical(17), viewport.Height), DeviceDpi);
|
||||
void Place(Control c, Rectangle r) { c.Bounds = r; }
|
||||
Rectangle R(int x, int y, int w, int h) => new(ScaleLogical(x), ScaleLogical(y), ScaleLogical(w), ScaleLogical(h));
|
||||
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(_dailyCard, layout.DailyCard); Place(_footer, layout.Footer);
|
||||
|
||||
_statusDot.Bounds = R(24, 15, 42, 46);
|
||||
_connectButton.Bounds = new(_statusCard.Width - ScaleLogical(148), ScaleLogical(17), ScaleLogical(130), ScaleLogical(42));
|
||||
var textWidth = _connectButton.Left - ScaleLogical(100);
|
||||
_statusTitle.Bounds = new(ScaleLogical(84), ScaleLogical(10), textWidth, ScaleLogical(33));
|
||||
_statusDetail.Bounds = new(ScaleLogical(85), ScaleLogical(43), textWidth, ScaleLogical(25));
|
||||
_nodeIcon.Bounds = R(26, 23, 24, 24); _modeIcon.Bounds = R(26, 23, 24, 24);
|
||||
_nodeHeading.Bounds = new(ScaleLogical(54), ScaleLogical(9), Math.Max(0, _nodeCard.Width - ScaleLogical(205)), ScaleLogical(23));
|
||||
_connectionModeCombo.Bounds = new(_nodeCard.Width - ScaleLogical(144), ScaleLogical(6), ScaleLogical(130), ScaleLogical(28));
|
||||
_manualNodeCombo.Bounds = new(ScaleLogical(54), ScaleLogical(34), _nodeCard.Width - ScaleLogical(68), ScaleLogical(28));
|
||||
var badgeWidth = ScaleLogical(88);
|
||||
var badgeX = _nodeCard.Width - badgeWidth - ScaleLogical(14);
|
||||
_currentNodeLabel.Bounds = new(ScaleLogical(54), ScaleLogical(34),
|
||||
_selectionUiConnected ? _nodeCard.Width - ScaleLogical(68) : badgeX - ScaleLogical(60), ScaleLogical(27));
|
||||
_scheduleBadge.Bounds = new(badgeX, ScaleLogical(35), badgeWidth, ScaleLogical(23));
|
||||
_routeHeading.Bounds = new(ScaleLogical(54), ScaleLogical(8), _modeCard.Width - ScaleLogical(70), ScaleLogical(22));
|
||||
_routeCombo.Bounds = new(ScaleLogical(54), ScaleLogical(33), _modeCard.Width - ScaleLogical(70), ScaleLogical(28));
|
||||
_routeReadOnly.Bounds = new(_routeCombo.Left, _routeCombo.Top, _routeCombo.Width, ScaleLogical(28));
|
||||
_trafficIcon.Bounds = R(15, 10, 20, 20); _dailyIcon.Bounds = R(15, 10, 20, 20);
|
||||
_trafficHeading.Bounds = R(42, 8, 92, 26);
|
||||
_sampleLabel.Bounds = new(ScaleLogical(132), ScaleLogical(10), _trafficCard.Width - ScaleLogical(146), ScaleLogical(22));
|
||||
_dailyHeading.Bounds = new(ScaleLogical(42), ScaleLogical(8), _dailyCard.Width - ScaleLogical(180), ScaleLogical(26));
|
||||
_historyRangeCombo.Bounds = new(_dailyCard.Width - ScaleLogical(140), ScaleLogical(10), ScaleLogical(124), ScaleLogical(26));
|
||||
_trafficChart.Bounds = new(ScaleLogical(13), ScaleLogical(132), _trafficCard.Width - ScaleLogical(26), ScaleLogical(106));
|
||||
_dailyChart.Bounds = new(ScaleLogical(13), ScaleLogical(132), _dailyCard.Width - ScaleLogical(26), ScaleLogical(106));
|
||||
var legendWidth = (_trafficCard.Width - ScaleLogical(40)) / 2;
|
||||
_uploadLegend.Bounds = new(ScaleLogical(20), ScaleLogical(248), legendWidth, ScaleLogical(19));
|
||||
_downloadLegend.Bounds = new(ScaleLogical(20) + legendWidth, ScaleLogical(248), legendWidth, ScaleLogical(19));
|
||||
_dailyUploadLegend.Bounds = new(ScaleLogical(20), ScaleLogical(248), ScaleLogical(52), ScaleLogical(19));
|
||||
_dailyDownloadLegend.Bounds = new(ScaleLogical(76), ScaleLogical(248), ScaleLogical(52), ScaleLogical(19));
|
||||
_historyStatus.Bounds = new(ScaleLogical(134), ScaleLogical(248), _dailyCard.Width - ScaleLogical(148), ScaleLogical(19));
|
||||
_planLabel.Bounds = R(0, 4, 300, 26);
|
||||
_expiryLabel.Bounds = R(306, 4, 132, 26);
|
||||
_footerCompanyLogo.Bounds = R(0, 34, 32, 34);
|
||||
_footerCompanySite.Bounds = R(0, 41, 220, 22);
|
||||
_footerHint.Visible = true;
|
||||
_footerHint.Bounds = new(ScaleLogical(232), ScaleLogical(39), Math.Max(1, _footer.Width - ScaleLogical(232)), ScaleLogical(28));
|
||||
_footerPoem.Visible = !layout.Compact && _footer.Width >= ScaleLogical(780);
|
||||
_footerPoem.Bounds = new(_footer.Width - ScaleLogical(322), ScaleLogical(5), ScaleLogical(322), ScaleLogical(29));
|
||||
_dashboardBody.Size = new Size(layout.StatusCard.Right + ScaleLogical(20), layout.ContentHeight);
|
||||
_dashboardScrollBar.Maximum = Math.Max(0, layout.ContentHeight - 1);
|
||||
_dashboardScrollBar.LargeChange = Math.Max(1, viewport.Height);
|
||||
_dashboardScrollBar.SmallChange = ScaleLogical(28);
|
||||
_dashboardScrollBar.Value = Math.Clamp(previousScroll, 0, Math.Max(0, layout.ContentHeight - viewport.Height));
|
||||
_dashboardBody.Location = new Point(0, -_dashboardScrollBar.Value);
|
||||
_dashboardScrollBar.BringToFront();
|
||||
}
|
||||
finally
|
||||
{
|
||||
foreach (var container in layoutContainers.Reverse()) container.ResumeLayout(false);
|
||||
_layingOutDashboard = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Isolated synthetic fixture: no stored account, core, system proxy, update query or installation.
|
||||
internal static void RenderPreview()
|
||||
{
|
||||
using var form = new MainForm(preview: true) { Opacity = 0, ShowInTaskbar = false };
|
||||
form.Show();
|
||||
form.ShowDashboard(new Profile
|
||||
{
|
||||
DisplayName = "示例用户", Email = "demo@example.com", IdentityType = "employee",
|
||||
Subscription = new SubscriptionInfo { Plan = "员工福利", UsedBytes = 17480516895, DeviceLimit = 3 },
|
||||
Nodes = [new NodeInfo { Name = "VPN003", Slug = "preview", Status = "online" }],
|
||||
RouteModes = [new RouteModeInfo { Id = "smart", Name = "AI 智能代理" }],
|
||||
UsageHistory = Enumerable.Range(0, 7).Select(i => new DailyUsage { Day = DateTime.Today.AddDays(i - 6).ToString("yyyy-MM-dd"), UploadBytes = new long[] { 14000000, 0, 0, 0, 3000000, 35000000, 196000000 }[i], DownloadBytes = new long[] { 28000000, 0, 0, 0, 26000000, 158000000, 126000000 }[i] }).ToList()
|
||||
});
|
||||
form._refreshTimer.Stop();
|
||||
var fixtureRanges = UsageHistoryPeriod.All.ToDictionary(p => p.Key, p => new UsageHistorySeries
|
||||
{
|
||||
Bucket = p.Bucket, Note = p.Bucket == "hour" ? "演示数据 · 按上报入账小时;缺口为无明细" : "演示数据 · 月筛选为近30个自然日",
|
||||
Points = Enumerable.Range(0, p.Count).Select(i => new UsageHistoryPoint
|
||||
{
|
||||
Time = p.Bucket == "hour" ? new DateTimeOffset(2026, 9, 9, 21, 0, 0, TimeSpan.FromHours(8)).AddHours(i - p.Count + 1).ToString("O")
|
||||
: new DateOnly(2026, 9, 9).AddDays(i - p.Count + 1).ToString("yyyy-MM-dd"),
|
||||
UploadBytes = p.Bucket == "hour" && i == 3 ? null : (long)((Math.Sin(i * .72) + 1.1) * 60_000_000),
|
||||
DownloadBytes = p.Bucket == "hour" && i == 3 ? null : (long)((Math.Cos(i * .81) + 1.1) * 84_000_000)
|
||||
}).ToList()
|
||||
});
|
||||
form._currentNodeLabel.Text = "VPN003";
|
||||
form.SetConnectionState(true, "已安全连接", "VPN003 · AI 智能代理");
|
||||
form.DisplayTraffic(91975, 23357, "21:13:00 · 近 5 分钟");
|
||||
form._sessionMetric.SetBytes(130180710, hint: "本次连接累计");
|
||||
for (var i = 0; i < 60; i++) form._trafficChart.Add((i % 13 == 0 ? 72 : 8 + Math.Sin(i * 1.8) * 4) * 1024,
|
||||
(i % 9 == 2 ? 130 : 10 + Math.Sin(i * 2.4) * 8) * 1024, DateTimeOffset.Now.AddSeconds((i - 59) * 5));
|
||||
form.LayoutBrandHeader(); form.LayoutDashboard();
|
||||
var checks = new Dictionary<string, bool> { ["geometry_56_viewport_dpi_cases"] = DashboardLayout.SelfTest() };
|
||||
foreach (var check in UsageHistorySeries.SelfTest()) checks[check.Key] = check.Value;
|
||||
void Capture(string suffix)
|
||||
{
|
||||
form.PerformLayout(); form.LayoutDashboard(); Application.DoEvents();
|
||||
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()}-{suffix}.png"));
|
||||
}
|
||||
Capture("dashboard");
|
||||
form._currentNodeName = NodePresentation.JinanName;
|
||||
form._currentNodeLabel.Text = form._currentNodeName;
|
||||
form.SetConnectionState(true, "已安全连接", form._currentNodeName + " · AI 智能代理");
|
||||
Capture("zero3-connected");
|
||||
checks["zero3_connected_name_fits"] = TextRenderer.MeasureText(form._currentNodeName, form._currentNodeLabel.Font).Width <= form._currentNodeLabel.Width;
|
||||
checks["dashboard_controls_within_cards"] = form.DashboardControlsFit();
|
||||
checks["footer_slogan_displays_without_company_brand"] = !form._brandHeader.Controls.Contains(form._footerCompanyLogo)
|
||||
&& form._footerCompanyLogo.Parent == form._footer && !form._footerCompanyLogo.Visible;
|
||||
checks["footer_slogan_text_has_no_url"] = form._footerCompanySite.Visible && form._footerCompanySite.Text == "智能连接 · 高效办公"
|
||||
&& !form._footerCompanySite.Text.Contains("vpn.", StringComparison.OrdinalIgnoreCase)
|
||||
&& !form._footerCompanySite.Text.Contains("://", StringComparison.OrdinalIgnoreCase);
|
||||
checks["official_header_logo_preserved"] = form._brandHeader.Controls.OfType<PictureBox>().Any(logo => logo.Visible && logo.Image is not null
|
||||
&& logo.SizeMode == PictureBoxSizeMode.Zoom && logo.Tag is Rectangle bounds && bounds == new Rectangle(20, 29, 62, 67)
|
||||
&& logo.Bounds == new Rectangle(form.ScaleLogical(20), form.ScaleLogical(29), form.ScaleLogical(62), form.ScaleLogical(67)));
|
||||
checks["product_header_named_zonghengjia"] = form.Text == "纵横家" && form._brandHeader.Controls.OfType<Label>().Any(label => label.Text == "纵横家");
|
||||
checks["powered_by_removed_from_login_and_footer"] = !form._footer.Controls.OfType<Label>().Concat(form._loginView.Controls.OfType<Label>())
|
||||
.Any(label => label.Text.Contains("Powered by", StringComparison.OrdinalIgnoreCase) || label.Text == "优创未来");
|
||||
checks["content_composes_child_painting"] = form._content.ComposeChildren;
|
||||
checks["header_only_has_minimize_button"] = form._brandHeader.Controls.OfType<CaptionButton>().Count() == 1;
|
||||
checks["scenic_asset_is_decoration_only"] = form._brandHeader.BackgroundImage is null && form._trafficChart.Parent == form._trafficCard;
|
||||
checks["scenic_artwork_packaged_in_exe"] = ScenicTheme.ArtworkAvailable;
|
||||
checks["footer_poem_does_not_overlap_plan"] = !form._footerPoem.Visible || form._footerPoem.Left > form._expiryLabel.Right;
|
||||
checks["internal_use_notice_visible"] = form._footerHint.Text == "仅限内部使用,不作商业使用。" && form._footerHint.Visible;
|
||||
checks["proxy_metrics_values"] = form._usageMetric.UnitText == "GB" && form._uploadMetric.UnitText == "KB/s" && form._sessionMetric.UnitText == "MB";
|
||||
checks["related_metrics_share_chart_parent"] = form._usageMetric.Parent == form._sessionMetric.Parent &&
|
||||
form._uploadMetric.Parent == form._trafficChart.Parent && form._downloadMetric.Parent == form._trafficChart.Parent;
|
||||
form._historyRangeCombo.SelectedIndex = 0;
|
||||
Capture("history-legacy-unavailable");
|
||||
checks["legacy_hourly_no_invented_curve"] = form._dailyChart.PointCount == 0;
|
||||
form._dailyChart.SetHistory([], fixtureRanges);
|
||||
foreach (var period in UsageHistoryPeriod.All)
|
||||
{
|
||||
form._historyRangeCombo.SelectedItem = period;
|
||||
Capture("history-" + period.Key);
|
||||
checks["filter_" + period.Key] = form._dailyChart.SelectedRange == period.Key && form._dailyChart.PointCount == period.Count;
|
||||
}
|
||||
form._dailyChart.SetHistory([], fixtureRanges);
|
||||
checks["profile_refresh_preserves_filter"] = form._dailyChart.SelectedRange == "30d";
|
||||
form._historyRangeCombo.SelectedIndex = 2;
|
||||
form.Size = form.MinimumSize;
|
||||
Capture("compact");
|
||||
checks["zero3_compact_name_fits"] = TextRenderer.MeasureText(form._currentNodeName, form._currentNodeLabel.Font).Width <= form._currentNodeLabel.Width;
|
||||
checks["compact_controls_within_cards"] = form.DashboardControlsFit();
|
||||
form._dashboardScrollBar.Value = Math.Max(0, form._dashboardScrollBar.Maximum - form._dashboardScrollBar.LargeChange + 1);
|
||||
Application.DoEvents();
|
||||
form.LayoutDashboard();
|
||||
checks["compact_footer_scrolls_into_view"] = form._footer.RectangleToScreen(form._footer.ClientRectangle).Bottom <= form._dashboardView.RectangleToScreen(form._dashboardView.ClientRectangle).Bottom;
|
||||
checks["compact_no_horizontal_scrollbar"] = !form._dashboardView.HorizontalScroll.Visible;
|
||||
Capture("compact-scrolled");
|
||||
form._dashboardScrollBar.Value = 0;
|
||||
form.ClientSize = new Size(form.ScaleLogical(900), form.ScaleLogical(640));
|
||||
form._currentNodeName = "VPN002";
|
||||
form._currentNodeLabel.Text = form._currentNodeName;
|
||||
form.SetConnectionState(true, "已安全连接", form._currentNodeName + " · 已回退到公共节点");
|
||||
Capture("public-fallback");
|
||||
checks["fallback_does_not_show_zero3"] = !form._statusDetail.Text.Contains("Zero3") && form._currentNodeLabel.Text == "VPN002";
|
||||
form.SetConnectionState(false, "未连接", "点击连接,自动选择工作节点");
|
||||
form._currentNodeLabel.Text = "连接后自动分配";
|
||||
form._trafficChart.Reset(); form._dailyChart.SetHistory([]);
|
||||
Capture("disconnected");
|
||||
checks["disconnected_speed_not_stale"] = form._uploadMetric.ValueText == "—" && form._downloadMetric.ValueText == "—";
|
||||
form._connectionModeCombo.SelectedIndex = 1;
|
||||
form._manualNodeCombo.SelectedIndex = 0;
|
||||
Capture("manual-selection");
|
||||
checks["manual_selection_controls_within_card"] = form.DashboardControlsFit();
|
||||
checks["manual_selection_visible_when_disconnected"] = form._manualNodeCombo.Visible && form._manualNodeCombo.Enabled;
|
||||
form.SetConnectionState(true, "已安全连接", "手动指定节点 · AI 智能代理");
|
||||
Capture("manual-connected");
|
||||
checks["manual_connected_selection_locked"] = !form._connectionModeCombo.Enabled && !form._manualNodeCombo.Visible;
|
||||
form.ShowLogin(); Capture("login");
|
||||
checks["login_fields_visible"] = form.LoginFieldsVisibleForTest;
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "dashboard-ui-self-test.json"), JsonSerializer.Serialize(new
|
||||
{
|
||||
version = GetDisplayVersion(), passed = checks.Values.All(v => v), checks,
|
||||
dpi = form.DeviceDpi, synthetic_data = true, network_modified = false, installed_client_modified = false
|
||||
}, new JsonSerializerOptions { WriteIndented = true }));
|
||||
form.RequestExit();
|
||||
if (checks.Values.Any(v => !v)) throw new InvalidOperationException("Dashboard UI self-test failed; inspect dashboard-ui-self-test.json");
|
||||
}
|
||||
|
||||
private bool DashboardControlsFit() => new Control[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _dailyCard, _footer }
|
||||
.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));
|
||||
}
|
||||
Reference in New Issue
Block a user