Publish Zonghengjia Windows 0.3.13 client source

This commit is contained in:
2026-11-13 10:35:04 +08:00
parent 1590443809
commit 839434a313
55 changed files with 2324 additions and 963 deletions
+69 -41
View File
@@ -18,7 +18,7 @@ internal sealed partial class MainForm
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 CardPanel _footer = new();
private readonly ScenicPanel _dashboardBody = new();
private readonly VScrollBar _dashboardScrollBar = new();
private readonly MetricCard _usageMetric = new("本期代理流量", DashboardIcon.Database);
@@ -26,7 +26,7 @@ internal sealed partial class MainForm
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 DashboardGlyph _trafficIcon = new(DashboardIcon.Chart), _dailyIcon = new(DashboardIcon.Chart);
private readonly Label _trafficHeading = new(), _dailyHeading = new(), _trendHeading = new();
private readonly CardPanel _speedTrendCard = new();
private bool _layingOutDashboard;
@@ -40,7 +40,7 @@ internal sealed partial class MainForm
{
_dashboardView.Dock = DockStyle.Fill;
_dashboardView.BackColor = Brand.Surface;
_dashboardView.LoginArtwork = true;
_dashboardView.DashboardArtwork = true;
_dashboardView.AutoScroll = false;
_dashboardView.Visible = false;
_dashboardView.Resize += (_, _) => LayoutDashboard();
@@ -72,7 +72,7 @@ internal sealed partial class MainForm
_dashboardBody.Controls.AddRange([_welcomeLabel, _accountLabel, _identityBadge, _logoutButton]);
ConfigureLabel(_statusTitle, "未连接", Brand.Font(17, FontStyle.Bold), Brand.Text);
ConfigureLabel(_statusDetail, "点击连接,自动选择工作节点", Brand.Font(9.5f), Brand.Muted);
ConfigureLabel(_statusDetail, "点击连接,自动选择工作节点", Brand.Font(11), Brand.Muted);
_statusDot.ForeColor = Brand.Muted;
_statusCard.ScenicStatus = true;
_nodeCard.AccentBar = _modeCard.AccentBar = false;
@@ -86,38 +86,40 @@ internal sealed partial class MainForm
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(9.5f, FontStyle.Bold), Brand.RoyalBlue);
ConfigureLabel(_selectionHeading, "调度", Brand.Font(7.5f), Brand.Muted);
ConfigureLabel(_actualModeHeading, "模式", Brand.Font(7.5f), Brand.Muted);
ConfigureLabel(_nodeHeading, "当前工作节点", Brand.Font(10.5f, FontStyle.Bold), Brand.Text);
ConfigureLabel(_routeHeading, "代理模式", Brand.Font(10.5f, FontStyle.Bold), Brand.Text);
ConfigureLabel(_currentNodeLabel, "未连接", Brand.Font(11, FontStyle.Bold), Brand.RoyalBlue);
ConfigureLabel(_selectionHeading, "调度", Brand.Font(10.5f, FontStyle.Bold), Brand.Text);
ConfigureLabel(_actualModeHeading, "模式", Brand.Font(10.5f, FontStyle.Bold), Brand.Text);
_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));
var x = WideDashboardPresentation ? _modeIcon.Left - ScaleLogical(7) : 0;
e.Graphics.DrawLine(divider, x, ScaleLogical(8), x, _modeCard.Height - ScaleLogical(8));
};
BuildConnectionSelection();
ConfigureCombo(_routeCombo, Point.Empty, new(220, 30));
_routeCombo.BackColor = Color.Transparent;
_routeCombo.AccessibleName = "代理模式(连接时不可更改)";
_routeReadOnly.Font = Brand.Font(10.5f, FontStyle.Bold);
_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(_dailyHeading, "累计流量", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
ConfigureLabel(_dailyHeading, "累计流量", Brand.Font(12, 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(_downloadLegend, "● 下载 —", Brand.Font(8), TrafficChart.DownloadColor);
ConfigureLabel(_historyStatus, "仅本次运行采样 · KB/s 起", Brand.Font(7), Brand.Muted);
_historyStatus.AutoEllipsis = true;
_historyStatus.TextAlign = ContentAlignment.MiddleRight;
_historyStatus.AccessibleDescription = "代理速度曲线仅为当前客户端实际采集的代理速度;右侧累计区只显示统计数字。";
ConfigureLabel(_trendHeading, "代理速度趋势", Brand.Font(8, FontStyle.Bold), Brand.Text);
ConfigureLabel(_trendHeading, "代理速度趋势", Brand.Font(11, FontStyle.Bold), Brand.Text);
_trafficCard.Controls.AddRange([_trafficIcon, _trafficHeading]);
_dailyCard.Controls.AddRange([_dailyIcon, _dailyHeading]);
_speedTrendCard.Controls.AddRange([_trendHeading, _trafficChart, _uploadLegend, _downloadLegend]);
@@ -141,13 +143,13 @@ internal sealed partial class MainForm
_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);
ConfigureLabel(_footerHint, "仅限内部使用,不作商业使用。", Brand.Font(8.5f), Brand.Muted);
_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);
ConfigureLabel(_footerCompanySite, PlatformBootstrapTransport.Host, 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, _trafficCard, _speedTrendCard, _dailyCard })
@@ -161,6 +163,7 @@ internal sealed partial class MainForm
BuildTailnetTrafficCard();
BuildNodeTrafficMonitor();
_dashboardBody.Controls.Add(_footer);
BuildWideDashboard();
foreach (var label in new[] { _welcomeLabel, _accountLabel, _statusTitle, _statusDetail, _currentNodeLabel, _planLabel, _expiryLabel })
{
label.AutoEllipsis = true;
@@ -180,6 +183,8 @@ internal sealed partial class MainForm
_sampleLabel.Text = sampling;
_uploadLegend.Text = "● 上传 " + SpeedDisplay.Format(upload);
_downloadLegend.Text = "● 下载 " + SpeedDisplay.Format(download);
_wideUpload.Text = "↑ 上传 " + SpeedDisplay.Format(upload);
_wideDownload.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);
@@ -187,20 +192,26 @@ internal sealed partial class MainForm
private void LayoutDashboard()
{
if (_layingOutDashboard || _dashboardView.ClientSize.Width <= 0) return;
if (!_wideDashboardBuilt || _layingOutDashboard || _dashboardView.ClientSize.Width <= 0) return;
_layingOutDashboard = true;
Control[] layoutContainers = [_dashboardView, _dashboardBody, _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _nodeTrafficPanel, _footer];
Control[] layoutContainers = [_dashboardView, _dashboardBody, _wideMonitor, _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);
var wide = WideDashboardPresentation && viewport.Height >= ScaleLogical(390);
SetStatusTitleFont(wide, viewport.Height < ScaleLogical(465));
_dashboardScrollBar.Visible = false;
_dashboardScrollBar.Value = 0;
_dashboardScrollBar.Maximum = 0;
SetDashboardPresentation(wide);
if (wide)
{
LayoutWideDashboard(viewport);
return;
}
var layout = DashboardLayout.Calculate(viewport, DeviceDpi, _tailnetTrafficVisible, _canViewNodeTraffic, true);
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);
@@ -226,6 +237,9 @@ internal sealed partial class MainForm
{
using var form = new MainForm(preview: true) { Opacity = 0, ShowInTaskbar = false };
form.Show();
Application.DoEvents();
var loginBounds = form.Bounds;
var loginClientSize = form.ClientSize;
form.ShowDashboard(new Profile
{
DisplayName="示例用户",Email="demo@example.com",IdentityType="employee",
@@ -234,17 +248,38 @@ internal sealed partial class MainForm
RouteModes=[new RouteModeInfo {Id="smart",Name="AI 智能代理"}]
});
form._refreshTimer.Stop();
var now=DateTimeOffset.UtcNow;
var serverClock=now;
using var previewServers=new NodeTrafficPanel(()=>serverClock) {Visible=false};
form._dashboardBody.Controls.Add(previewServers);
var showServerFixture=false;
void Capture(string suffix)
{
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.ClientSize.Width,form.ClientSize.Height);
form.DrawToBitmap(image,new Rectangle(Point.Empty,image.Size));
image.Save(Path.Combine(AppContext.BaseDirectory,$"preview-{GetDisplayVersion()}-{form.DeviceDpi}dpi-{suffix}.png"));
}
Capture("compact-dashboard-after-login");
var dashboardBounds = form.Bounds;
var dashboardClientSize = form.ClientSize;
var initialDashboardFits = form._dashboardView.Visible && !form._loginView.Visible
&& form.CompactPresentation && form.DashboardControlsFit();
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 分钟");
@@ -252,6 +287,8 @@ internal sealed partial class MainForm
var checks=new Dictionary<string,bool>
{
["geometry_all_viewport_and_dpi_cases"]=DashboardLayout.SelfTest(),
["dashboard_after_login_retains_initial_window_bounds"] = loginBounds == dashboardBounds && loginClientSize == dashboardClientSize,
["dashboard_after_login_fits_initial_compact_window"] = initialDashboardFits,
["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"),
@@ -263,24 +300,10 @@ internal sealed partial class MainForm
["controls_fit"]=form.DashboardControlsFit(),
["half_transparent_surfaces"]=CardPanel.SurfaceAlpha==128
};
void Capture(string suffix)
{
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"));
}
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("域名入口")
checks["public_ingress_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);
@@ -338,18 +361,23 @@ internal sealed partial class MainForm
form.SetConnectionState(false,"未连接","连接后显示代理速度趋势");
form._trafficChart.Reset();Capture("disconnected");
checks["disconnected_values_not_stale"]=form._uploadLegend.Text.Contains("—")&&form._downloadLegend.Text.Contains("—");
showServerFixture=false;
previewServers.Visible=false;
form.ExerciseWideDashboardPreview(checks, Capture);
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
{
version=GetDisplayVersion(),passed=checks.Values.All(value=>value),checks,dpi=form.DeviceDpi,
login_client_size = new { width = loginClientSize.Width, height = loginClientSize.Height },
dashboard_client_size = new { width = dashboardClientSize.Width, height = dashboardClientSize.Height },
synthetic_data=true,network_modified=false,installed_client_modified=false,production_sample_observed=false
},new JsonSerializerOptions {WriteIndented=true}));
form.RequestExit();
if(checks.Values.Any(value=>!value))throw new InvalidOperationException("Dashboard UI self-test failed; inspect dashboard-ui-self-test.json");
}
private bool DashboardControlsFit() => new Control[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _footer }
private bool DashboardControlsFit() => new Control[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _footer, _wideMonitor, _wideSummary }
.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));
}