Windows 0.3.3 dashboard layout and speed presentation source delta; no private history or other platform changes

This commit is contained in:
2026-11-03 15:15:23 +00:00
parent bfe8d6c62a
commit aff1a50d35
32 changed files with 1673 additions and 652 deletions
+63 -83
View File
@@ -11,7 +11,8 @@ internal sealed partial class MainForm
private readonly Label _downloadLegend = new();
private readonly Label _historyStatus = new();
private readonly ReadOnlyModeLabel _routeReadOnly = new();
private readonly ComboBox _historyRangeCombo = new();
private readonly DashboardCombo _historyRangeCombo = new();
private readonly Label _selectionHeading = new(), _actualModeHeading = new();
private readonly Label _footerHint = new();
private readonly Label _footerPoem = new();
private readonly PictureBox _footerCompanyLogo = new();
@@ -56,7 +57,7 @@ internal sealed partial class MainForm
// Moving a canvas must repaint them, not bit-blit old transparent pixels.
_dashboardBody.Invalidate(true);
};
ConfigureLabel(_welcomeLabel, "", Brand.Font(15, FontStyle.Bold), Brand.Navy);
ConfigureLabel(_welcomeLabel, "", Brand.Font(11, 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);
@@ -74,7 +75,8 @@ internal sealed partial class MainForm
ConfigureLabel(_statusDetail, "点击连接,自动选择工作节点", Brand.Font(9.5f), Brand.Muted);
_statusDot.ForeColor = Brand.Muted;
_statusCard.ScenicStatus = true;
_nodeCard.AccentBar = _modeCard.AccentBar = true;
_nodeCard.AccentBar = _modeCard.AccentBar = false;
_modeCard.Embedded = true;
_trafficCard.MetricBand = _dailyCard.MetricBand = false;
ConfigurePrimaryButton(_connectButton, "连接", Point.Empty, new(130, 42));
_connectButton.Click += async (_, _) =>
@@ -86,23 +88,32 @@ internal sealed partial class MainForm
_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]);
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));
};
BuildConnectionSelection();
ConfigureCombo(_routeCombo, Point.Empty, new(220, 30));
_routeCombo.BackColor = Color.White;
_routeCombo.BackColor = Color.Transparent;
_routeCombo.AccessibleName = "代理模式(连接时不可更改)";
_routeReadOnly.Visible = false;
_modeCard.Controls.AddRange([_modeIcon, _routeHeading, _routeCombo, _routeReadOnly]);
_routeReadOnly.Visible = true;
_routeReadOnly.ForeColor = Brand.DeepBlue;
_nodeCard.Controls.Add(_routeCombo);
ConfigureLabel(_trafficHeading, "公网入口速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
_trafficCard.AccessibleDescription = "仅当前纵横家使用域名或公网入口的代理速度;Tailscale 入口速度另列,非整机流量。";
ConfigureLabel(_trafficHeading, "代理实时速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
_trafficCard.AccessibleDescription = "纵横家当前全部代理速度,包含当前 Tailscale 传输;非整机流量。";
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(_historyStatus, "仅本次运行采样 · B/s", Brand.Font(7), Brand.Muted);
ConfigureLabel(_historyStatus, "仅本次运行采样 · KB/s 起", Brand.Font(7), Brand.Muted);
_historyStatus.AutoEllipsis = true;
_historyStatus.TextAlign = ContentAlignment.MiddleRight;
_historyStatus.AccessibleDescription = "代理速度曲线仅为当前客户端实际采集的代理速度;右侧累计区只显示统计数字。";
@@ -114,19 +125,8 @@ internal sealed partial class MainForm
// byte totals are no longer drawn as a misleading speed history.
_dailyChart.Visible = false;
ConfigureCombo(_historyRangeCombo, Point.Empty, new(120, 28));
_historyRangeCombo.BackColor = Color.White;
_historyRangeCombo.BackColor = Color.Transparent;
_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(SpeedHistoryPeriod.All);
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[1];
@@ -146,7 +146,7 @@ internal sealed partial class MainForm
ConfigureLabel(_footerCompanySite, "vpn.example.invalid", 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, _speedTrendCard, _dailyCard })
foreach (var card in new CardPanel[] { _statusCard, _nodeCard, _trafficCard, _speedTrendCard, _dailyCard })
{
card.BackColor = Color.White;
_dashboardBody.Controls.Add(card);
@@ -171,14 +171,11 @@ internal sealed partial class MainForm
private void DisplayTraffic(double? upload, double? download, string sampling)
{
var publicUpload = _currentNodeUsesTailnet ? null : upload;
var publicDownload = _currentNodeUsesTailnet ? null : download;
var hint = _currentNodeUsesTailnet ? "未使用公网入口" : "";
_uploadMetric.SetBytes(publicUpload, speed: true, hint: hint);
_downloadMetric.SetBytes(publicDownload, speed: true, hint: hint);
_uploadMetric.SetBytes(upload, speed: true, hint: "代理总速度");
_downloadMetric.SetBytes(download, speed: true, hint: "代理总速度");
_sampleLabel.Text = sampling;
_uploadLegend.Text = upload.HasValue ? $"● 上传 {FormatBytes((long)upload.Value)}/s" : "● 上传 —";
_downloadLegend.Text = download.HasValue ? $"● 下载 {FormatBytes((long)download.Value)}/s" : "● 下载 —";
_uploadLegend.Text = "● 上传 " + SpeedDisplay.Format(upload);
_downloadLegend.Text = "● 下载 " + SpeedDisplay.Format(download);
// 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);
@@ -200,9 +197,7 @@ internal sealed partial class MainForm
_dashboardScrollBar.Visible = false;
_dashboardScrollBar.Value = 0;
_dashboardScrollBar.Maximum = 0;
int Y(int value) => Math.Max(0, (int)Math.Floor(ScaleLogical(value) * layout.VerticalScale));
void Place(Control c, Rectangle r) { c.Bounds = r; }
Rectangle R(int x, int y, int w, int h) => new(ScaleLogical(x), Y(y), ScaleLogical(w), Y(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);
@@ -210,51 +205,10 @@ internal sealed partial class MainForm
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);
LayoutTailnetTrafficCard(layout.TailnetTrafficCard, layout.VerticalScale);
if (CompactPresentation) { LayoutCompactDashboard(layout); return; }
_nodeIcon.Visible=_modeIcon.Visible=_trafficIcon.Visible=_dailyIcon.Visible=true;
_uploadLegend.Visible=_downloadLegend.Visible=true;
_tailnetTrafficIcon.Visible=true;
_scheduleBadge.Visible=!_manualNodeCombo.Visible&&!_selectionUiConnected;
_statusDot.Bounds = R(24, 15, 42, 46);
_connectButton.Bounds = new(_statusCard.Width - ScaleLogical(148), Y(17), ScaleLogical(130), Y(42));
var textWidth = _connectButton.Left - ScaleLogical(100);
_statusTitle.Bounds = new(ScaleLogical(84), Y(10), textWidth, Y(33));
_statusDetail.Bounds = new(ScaleLogical(85), Y(43), textWidth, Y(25));
_nodeIcon.Bounds = R(26, 23, 24, 24); _modeIcon.Bounds = R(26, 23, 24, 24);
_nodeHeading.Bounds = new(ScaleLogical(54), Y(9), Math.Max(0, _nodeCard.Width - ScaleLogical(205)), Y(23));
_nodeHeading.Text = layout.Compact ? "工作节点" : "当前工作节点";
_connectionModeCombo.Bounds = new(_nodeCard.Width - ScaleLogical(144), Y(6), ScaleLogical(130), Y(28));
_manualNodeCombo.Bounds = new(ScaleLogical(54), Y(34), _nodeCard.Width - ScaleLogical(68), Y(28));
var badgeWidth = ScaleLogical(88);
var badgeX = _nodeCard.Width - badgeWidth - ScaleLogical(14);
_currentNodeLabel.Bounds = new(ScaleLogical(54), Y(34),
_selectionUiConnected ? _nodeCard.Width - ScaleLogical(68) : badgeX - ScaleLogical(60), Y(27));
_scheduleBadge.Bounds = new(badgeX, Y(35), badgeWidth, Y(23));
_routeHeading.Bounds = new(ScaleLogical(54), Y(8), _modeCard.Width - ScaleLogical(70), Y(22));
_routeCombo.Bounds = new(ScaleLogical(54), Y(33), _modeCard.Width - ScaleLogical(70), Y(28));
_routeReadOnly.Bounds = new(_routeCombo.Left, _routeCombo.Top, _routeCombo.Width, Y(28));
_trafficIcon.Bounds = R(15, 10, 20, 20); _dailyIcon.Bounds = R(15, 10, 20, 20);
_trafficHeading.Bounds = R(42, 8, 150, 26);
_dailyHeading.Bounds = new(ScaleLogical(42), Y(8), Math.Max(1, _dailyCard.Width - ScaleLogical(166)), Y(26));
_trendHeading.Bounds = new(ScaleLogical(10),Y(4),Math.Max(1,_speedTrendCard.Width-ScaleLogical(132)),Y(21));
_historyRangeCombo.Bounds = new(_speedTrendCard.Width-ScaleLogical(110),Y(3),ScaleLogical(100),Y(24));
_trafficChart.Bounds = new(ScaleLogical(5),Y(28),_speedTrendCard.Width-ScaleLogical(10),Math.Max(Y(38),_speedTrendCard.Height-Y(50)));
var legendWidth = (_speedTrendCard.Width-ScaleLogical(16))/2;
_uploadLegend.Bounds = new(ScaleLogical(8),_speedTrendCard.Height-Y(20),legendWidth,Y(18));
_downloadLegend.Bounds = new(ScaleLogical(8)+legendWidth,_speedTrendCard.Height-Y(20),legendWidth,Y(18));
_historyStatus.Visible=false;
_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), Y(39), Math.Max(1, _footer.Width - ScaleLogical(232)), Y(28));
_footerPoem.Visible = !layout.Compact && _footer.Width >= ScaleLogical(780);
_footerPoem.Bounds = new(_footer.Width - ScaleLogical(322), Y(5), ScaleLogical(322), Y(29));
_dashboardBody.Size = viewport;
_dashboardBody.Location = Point.Empty;
_tailnetTrafficCard.Bounds=layout.TailnetTrafficCard;
_tailnetTrafficCard.Visible=_tailnetTrafficVisible;
_tailnetSampleLabel.Visible=false;
LayoutCompactDashboard(layout);
}
finally
{
@@ -302,7 +256,7 @@ internal sealed partial class MainForm
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"));
image.Save(Path.Combine(AppContext.BaseDirectory, $"preview-{GetDisplayVersion()}-{form.DeviceDpi}dpi-{suffix}.png"));
}
Capture("dashboard");
checks["default_window_width_and_height_halved"] = form.ClientSize==new Size(form.ScaleLogical(480),form.ScaleLogical(360));
@@ -373,7 +327,7 @@ internal sealed partial class MainForm
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._currentNodeLabel.Text = "未连接";
form._trafficChart.Reset(); form._dailyChart.SetHistory([]);
Capture("disconnected");
checks["disconnected_speed_not_stale"] = form._uploadMetric.ValueText == "—" && form._downloadMetric.ValueText == "—";
@@ -406,8 +360,8 @@ internal sealed partial class MainForm
form.DisplayTraffic(23842, 89312, "演示样本 · 近 5 分钟");
form.DisplayTailnetTraffic(23842, 89312, "演示样本 · 近 5 分钟");
Capture("tailnet-dashboard");
checks["tailnet_wide_preview_has_left_two_right_one"] = form._dailyCard.Top == form._trafficCard.Top
&& form._dailyCard.Bottom == form._speedTrendCard.Bottom;
checks["tailnet_preview_has_full_width_rows_and_compact_totals"] = form._dailyCard.Width == form._trafficCard.Width
&& form._dailyCard.Top > form._tailnetTrafficCard.Bottom && form._dailyCard.Height <= form.ScaleLogical(40);
form.Size = form.MinimumSize;
Capture("tailnet-compact");
form._dashboardScrollBar.Value = Math.Max(0, form._dashboardScrollBar.Maximum - form._dashboardScrollBar.LargeChange + 1);
@@ -416,11 +370,37 @@ internal sealed partial class MainForm
<= form._dashboardView.RectangleToScreen(form._dashboardView.ClientRectangle).Bottom;
form.ClientSize=new Size(form.ScaleLogical(480),form.ScaleLogical(360));
form.SetNodeTrafficPermission(true);
var serverSampledAt=DateTimeOffset.UtcNow;
form._nodeTrafficPanel.SetSnapshot(new NodeTrafficSnapshot
{
Contract=1, Scope="server_host_interface", Source="linux_host_interface", Direction="interface_perspective",
CounterSince="boot_or_interface_reset", GeneratedAt=serverSampledAt,
Nodes=NodeTrafficPresentation.Slugs.Select((slug,index)=>new NodeTrafficReading
{
Slug=slug, UploadRate=index==0?1_572_864:625_664, DownloadRate=index==0?23_842:8_388_608,
TotalUpload=index==0?137_813_120_000:921_845_760_000, TotalDownload=index==0?774_618_173_440:1_320_000_000_000,
SampledAt=serverSampledAt, IntervalSeconds=5, CounterEpoch="synthetic-preview"
}).ToList()
});
form.LayoutDashboard(); Capture("half-size-tailnet-servers");
checks["half_size_tailnet_servers_fit"] = form.DashboardControlsFit() && !form._dashboardScrollBar.Visible
&& form._nodeTrafficPanel.Bottom<form._footer.Top;
form.SetNodeTrafficPermission(false);
form.SetTailnetTrafficVisibility(false);
form.UpdateConnectedTransportPresentation(false);
form.SetConnectionState(false, "未连接", "连接后显示当前工作节点与代理模式");
Capture("half-size-disconnected-auto");
form._connectionModeCombo.SelectedIndex=1;
form._manualNodeCombo.SelectedIndex=0;
Capture("half-size-disconnected-manual");
checks["configuration_choices_left_actual_state_right"] = form._routeCombo.Right < form._modeCard.Left
&& form._connectionModeCombo.Right < form._modeCard.Left
&& form._currentNodeLabel.Text=="未连接" && form._routeReadOnly.Text=="未生效";
checks["configuration_rows_do_not_overlap"] = !form._connectionModeCombo.Bounds.IntersectsWith(form._routeCombo.Bounds)
&& !form._manualNodeCombo.Bounds.IntersectsWith(form._routeCombo.Bounds);
form.SetConnectionState(true,"已安全连接","VPN003 · AI 智能代理");
Capture("half-size-connected-manual");
form._connectionModeCombo.SelectedIndex=0;
Capture("half-size-connected-auto");
form.ShowLogin(); Capture("half-size-login");
checks["half_size_login_visible"] = form.LoginFieldsVisibleForTest && form.LoginRegistrationAlignedForTest;
form.ClientSize = new Size(form.ScaleLogical(900), form.ScaleLogical(640));