Publish Zonghengjia Windows 0.3.18 client source
This commit is contained in:
@@ -118,9 +118,8 @@ internal sealed partial class MainForm
|
||||
var isWide = WideDashboardPresentation;
|
||||
var rowFits = _currentNodeLabel.Visible && _modeCard.ClientRectangle.Contains(_currentNodeLabel.Bounds)
|
||||
&& _nodeHeading.Right <= _currentNodeLabel.Left
|
||||
&& (isWide
|
||||
? _currentNodeLabel.Right <= _modeIcon.Left && _routeReadOnly.Right <= _historyRangeCombo.Left
|
||||
: _currentNodeLabel.Bottom <= _routeReadOnly.Top);
|
||||
&& _currentNodeLabel.Bottom <= _routeReadOnly.Top
|
||||
&& (!isWide || !_wideSummaryState.Visible || _currentNodeLabel.Right <= _wideSummaryState.Left);
|
||||
result["connected_node_does_not_overlap_mode_or_range_" + label] = rowFits;
|
||||
result["connected_node_name_fits_" + label] = _currentNodeLabel.Text == NodePresentation.JinanName && FitsNodeText();
|
||||
allConnectedLayoutsFit &= rowFits && FitsNodeText();
|
||||
|
||||
@@ -145,7 +145,7 @@ internal sealed class MetricCard : CardPanel
|
||||
using var divider = new Pen(Color.FromArgb(145, 148, 188, 218), Math.Max(1, s * .7f));
|
||||
g.DrawLine(divider, 0, S(12), 0, Height - S(12));
|
||||
using var heading = Brand.Font(10);
|
||||
using var value = Brand.Font(Width < S(190) ? 13 : 17, FontStyle.Bold);
|
||||
using var value = Brand.Font(12, FontStyle.Bold);
|
||||
var inlineFlags = ChartAxis.PaintFlags | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter
|
||||
| TextFormatFlags.NoPadding | TextFormatFlags.EndEllipsis;
|
||||
var headingWidth = S(39);
|
||||
|
||||
@@ -41,6 +41,21 @@ internal sealed partial class MainForm
|
||||
PerformLayout();
|
||||
LayoutDashboard();
|
||||
Application.DoEvents();
|
||||
checks["compact_chrome_has_only_minimize_caption"] = WindowChromeForTest is
|
||||
{ LoginMode: false, MinimizeButton.Action: CaptionAction.Minimize }
|
||||
&& _brandHeader.Controls.OfType<CaptionButton>().Count(button => button.Visible) == 1
|
||||
&& !_brandHeader.Controls.OfType<Button>().Any(button => button.Visible && button.AccessibleName == "断开并退出");
|
||||
checks["compact_header_no_truncated_greeting"] = !_welcomeLabel.Visible
|
||||
&& _dashboardMore.Visible && _logoutButton.Visible;
|
||||
_dashboardMore.PerformClick();
|
||||
Application.DoEvents();
|
||||
checks["compact_settings_identifies_current_account"] = _settingsMenu?.Items.OfType<ToolStripLabel>()
|
||||
.Any(item => item.Text?.Contains(profile.Email, StringComparison.Ordinal) == true) == true;
|
||||
_settingsMenu?.Close();
|
||||
checks["compact_graph_top_controls_share_one_row"] = _trendHeading.Top == _uploadLegend.Top
|
||||
&& _uploadLegend.Top == _downloadLegend.Top && _downloadLegend.Top == _historyRangeCombo.Top
|
||||
&& _trendHeading.Right <= _uploadLegend.Left && _uploadLegend.Right <= _downloadLegend.Left
|
||||
&& _downloadLegend.Right <= _historyRangeCombo.Left;
|
||||
int Limit() => Math.Max(0, _dashboardScrollBar.Maximum - _dashboardScrollBar.LargeChange + 1);
|
||||
bool Wheel(Control target, int delta, Point? screenPoint = null)
|
||||
{
|
||||
|
||||
@@ -30,16 +30,18 @@ internal static class DashboardLayout
|
||||
var traffic = Rectangle.Empty;
|
||||
var tailnet = Rectangle.Empty;
|
||||
var footer = new Rectangle(margin, viewport.Height - margin - S(18), width, S(18));
|
||||
var daily = new Rectangle(margin, footer.Top - gap - S(22), width, S(22));
|
||||
var daily = new Rectangle(margin, footer.Top - gap - S(20), width, S(20));
|
||||
var trendTop = configuration.Bottom + gap;
|
||||
var graphHeight = Math.Max(S(72), daily.Top - gap - trendTop);
|
||||
var serverHeight = showServerTraffic ? Math.Min(S(100), (int)Math.Round((graphHeight-gap)*.52)) : 0;
|
||||
var trend = new Rectangle(margin, trendTop, width, graphHeight - (showServerTraffic ? serverHeight+gap : 0));
|
||||
var servers = showServerTraffic ? new Rectangle(margin, trend.Bottom+gap, width, serverHeight) : Rectangle.Empty;
|
||||
var headingWidth = S(120);
|
||||
var speedWidth = (width - headingWidth - S(10)) / 2;
|
||||
Rectangle Speed(int column) => new(headingWidth + column * speedWidth, 0, speedWidth, S(22));
|
||||
Rectangle Total(int column) => new(headingWidth + column * speedWidth, 0, speedWidth, daily.Height - S(2));
|
||||
var headingWidth = S(106);
|
||||
var columnWidth = (width - headingWidth - S(10)) / 2;
|
||||
var metricWidth = Math.Min(S(138), columnWidth);
|
||||
int MetricLeft(int column) => headingWidth + column * columnWidth + (columnWidth - metricWidth) / 2;
|
||||
Rectangle Speed(int column) => new(MetricLeft(column), 0, metricWidth, S(20));
|
||||
Rectangle Total(int column) => new(MetricLeft(column), 0, metricWidth, daily.Height - S(2));
|
||||
Rectangle[] metrics = [Total(0), Speed(0), Speed(1), Total(1)];
|
||||
return new(welcome, account, identity, logout, status, configuration, actual, metrics,
|
||||
traffic, tailnet, trend, daily, servers, footer, viewport.Height, true, 1f);
|
||||
|
||||
@@ -1,66 +1,67 @@
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal readonly record struct DashboardWideLayout(Rectangle Banner, Rectangle Sidebar, Rectangle Monitor,
|
||||
Rectangle State, Rectangle Trend, Rectangle Servers, Rectangle Totals, Rectangle Footer)
|
||||
{
|
||||
// State, Trend, Servers and Totals are relative to the monitor card.
|
||||
internal static DashboardWideLayout Calculate(Size size, int dpi, bool showServers)
|
||||
{
|
||||
int S(double logical) => (int)Math.Round(logical * dpi / 96d);
|
||||
var dense = size.Height < S(465);
|
||||
var margin = S(dense ? 16 : 20);
|
||||
var gap = S(dense ? 8 : 12);
|
||||
var width = size.Width - 2 * margin;
|
||||
var banner = new Rectangle(margin, S(4), width, Math.Clamp(size.Height / 7, S(dense ? 56 : 68), S(dense ? 68 : 92)));
|
||||
var footer = new Rectangle(margin, size.Height - S(dense ? 40 : 52), width, S(dense ? 32 : 40));
|
||||
var middleTop = banner.Bottom + gap;
|
||||
var middleHeight = footer.Top - gap - middleTop;
|
||||
var leftWidth = Math.Clamp((int)(width * .252), S(212), S(320));
|
||||
var sidebar = new Rectangle(margin, middleTop, leftWidth, middleHeight);
|
||||
var monitor = new Rectangle(sidebar.Right + gap, middleTop, width - leftWidth - gap, middleHeight);
|
||||
var inset = S(dense ? 6 : 8);
|
||||
var innerWidth = monitor.Width - 2 * inset;
|
||||
var state = new Rectangle(inset, inset, innerWidth, S(dense ? 36 : 44));
|
||||
var totalHeight = S(dense ? 45 : 62);
|
||||
var totals = new Rectangle(inset, monitor.Height - inset - totalHeight, innerWidth, totalHeight);
|
||||
var serverHeight = showServers ? Math.Clamp(monitor.Height / 4, S(dense ? 66 : 90), S(dense ? 100 : 144)) : 0;
|
||||
var servers = showServers
|
||||
? new Rectangle(inset, totals.Top - inset - serverHeight, innerWidth, serverHeight)
|
||||
: Rectangle.Empty;
|
||||
var trendBottom = (showServers ? servers.Top : totals.Top) - inset;
|
||||
var trend = new Rectangle(inset, state.Bottom + S(4), innerWidth, trendBottom - state.Bottom - S(4));
|
||||
return new(banner, sidebar, monitor, state, trend, servers, totals, footer);
|
||||
}
|
||||
|
||||
internal static bool SelfTest()
|
||||
{
|
||||
foreach (var dpi in new[] { 96, 120, 144, 192, 240, 288 })
|
||||
foreach (var width in new[] { 840, 960, 1160, 1440 })
|
||||
foreach (var height in new[] { 390, 420, 465, 515, 650, 850 })
|
||||
foreach (var servers in new[] { false, true })
|
||||
{
|
||||
var size = new Size(width * dpi / 96, height * dpi / 96);
|
||||
var layout = Calculate(size, dpi, servers);
|
||||
Rectangle[] outer = [layout.Banner, layout.Sidebar, layout.Monitor, layout.Footer];
|
||||
Rectangle[] inner = servers
|
||||
? [layout.State, layout.Trend, layout.Servers, layout.Totals]
|
||||
: [layout.State, layout.Trend, layout.Totals];
|
||||
if (!Fits(outer, size) || !Fits(inner, layout.Monitor.Size)) return false;
|
||||
var controlRows = height < 465 ? 41 : 51;
|
||||
if (layout.Trend.Height <= controlRows * dpi / 96 || layout.Sidebar.Height != layout.Monitor.Height) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
static bool Fits(Rectangle[] cards, Size size)
|
||||
{
|
||||
var bounds = new Rectangle(Point.Empty, size);
|
||||
for (var i = 0; i < cards.Length; i++)
|
||||
{
|
||||
if (cards[i].IsEmpty || !bounds.Contains(cards[i])) return false;
|
||||
for (var j = i + 1; j < cards.Length; j++)
|
||||
if (cards[i].IntersectsWith(cards[j])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal readonly record struct DashboardWideLayout(Rectangle Banner, Rectangle Configuration, Rectangle Monitor,
|
||||
Rectangle State, Rectangle Trend, Rectangle Servers, Rectangle Totals, Rectangle Footer)
|
||||
{
|
||||
// State belongs to the configuration card. The remaining panels belong to the monitor.
|
||||
internal static DashboardWideLayout Calculate(Size size, int dpi, bool showServers, bool showManualNode = false)
|
||||
{
|
||||
int S(double logical) => (int)Math.Round(logical * dpi / 96d);
|
||||
var dense = size.Height < S(465);
|
||||
var margin = S(dense ? 13 : 20);
|
||||
var gap = S(dense ? 6 : 10);
|
||||
var width = size.Width - 2 * margin;
|
||||
var banner = new Rectangle(margin, S(3), width, S(dense ? 53 : 62));
|
||||
var footer = new Rectangle(margin, size.Height - S(dense ? 31 : 40), width, S(dense ? 25 : 31));
|
||||
var middleTop = banner.Bottom + gap;
|
||||
var rowHeight = S(dense ? 26 : 31);
|
||||
var configuration = new Rectangle(margin, middleTop, width, rowHeight * (showManualNode ? 3 : 2) + S(10));
|
||||
var stateLeft = (int)(width * .48);
|
||||
var state = new Rectangle(stateLeft, S(5), width - stateLeft - S(12), rowHeight * 2);
|
||||
var monitorTop = configuration.Bottom + gap;
|
||||
var monitor = new Rectangle(margin, monitorTop, width, footer.Top - gap - monitorTop);
|
||||
var totalHeight = S(dense ? 30 : 38);
|
||||
var totals = new Rectangle(0, monitor.Height - totalHeight, width, totalHeight);
|
||||
var serverHeight = showServers ? Math.Clamp(monitor.Height / 3, S(dense ? 58 : 80), S(dense ? 105 : 150)) : 0;
|
||||
var servers = showServers
|
||||
? new Rectangle(0, totals.Top - gap - serverHeight, width, serverHeight)
|
||||
: Rectangle.Empty;
|
||||
var trendBottom = (showServers ? servers.Top : totals.Top) - gap;
|
||||
var trend = new Rectangle(0, 0, width, trendBottom);
|
||||
return new(banner, configuration, monitor, state, trend, servers, totals, footer);
|
||||
}
|
||||
|
||||
internal static bool SelfTest()
|
||||
{
|
||||
foreach (var dpi in new[] { 96, 120, 144, 192, 240, 288 })
|
||||
foreach (var width in new[] { 840, 960, 1160, 1440 })
|
||||
foreach (var height in new[] { 390, 420, 465, 515, 650, 850 })
|
||||
foreach (var servers in new[] { false, true })
|
||||
foreach (var manualNode in new[] { false, true })
|
||||
{
|
||||
var size = new Size(width * dpi / 96, height * dpi / 96);
|
||||
var layout = Calculate(size, dpi, servers, manualNode);
|
||||
Rectangle[] outer = [layout.Banner, layout.Configuration, layout.Monitor, layout.Footer];
|
||||
Rectangle[] inner = servers
|
||||
? [layout.Trend, layout.Servers, layout.Totals]
|
||||
: [layout.Trend, layout.Totals];
|
||||
if (!Fits(outer, size) || !Fits(inner, layout.Monitor.Size)
|
||||
|| !new Rectangle(Point.Empty, layout.Configuration.Size).Contains(layout.State)) return false;
|
||||
if (layout.Trend.Height < 80 * dpi / 96 || layout.Trend.Width != layout.Banner.Width
|
||||
|| layout.Totals.Height > Math.Ceiling(38 * dpi / 96d)) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
static bool Fits(Rectangle[] cards, Size size)
|
||||
{
|
||||
var bounds = new Rectangle(Point.Empty, size);
|
||||
for (var i = 0; i < cards.Length; i++)
|
||||
{
|
||||
if (cards[i].IsEmpty || !bounds.Contains(cards[i])) return false;
|
||||
for (var j = i + 1; j < cards.Length; j++)
|
||||
if (cards[i].IntersectsWith(cards[j])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+339
-348
@@ -1,348 +1,339 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal sealed partial class MainForm
|
||||
{
|
||||
private WindowChrome? _windowChrome;
|
||||
private ContextMenuStrip? _settingsMenu;
|
||||
private long _settingsDismissedAt = long.MinValue;
|
||||
private readonly DashboardHeaderIdentity _dashboardHeaderName = new();
|
||||
private readonly DashboardHeaderButton _dashboardSettings = new("设置", DashboardHeaderIcon.Settings);
|
||||
private readonly DashboardHeaderButton _dashboardAbout = new("关于", DashboardHeaderIcon.About);
|
||||
private readonly DashboardHeaderButton _dashboardLogout = new("退出账号", DashboardHeaderIcon.Logout);
|
||||
private readonly DashboardHeaderButton _dashboardMore = new("", DashboardHeaderIcon.Settings)
|
||||
{ AccessibleName = "设置" };
|
||||
private readonly DashboardHeaderButton _dashboardClose = new("", DashboardHeaderIcon.Close)
|
||||
{ AccessibleName = "断开并退出" };
|
||||
internal WindowChrome? WindowChromeForTest => _windowChrome;
|
||||
|
||||
// Remove the native caption before HWND creation, not only after its first
|
||||
// style/paint messages. This avoids a transient second caption at startup.
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
var parameters = base.CreateParams;
|
||||
parameters.Style = unchecked((int)ChromeNative.ClientChromeStyle(parameters.Style));
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
LayoutBrandHeader();
|
||||
CenterCards();
|
||||
LayoutDashboard();
|
||||
}
|
||||
|
||||
// Explicit title/tray Exit and installer IPC share the graceful exit path.
|
||||
private void InitializeWindowChrome(Panel header)
|
||||
{
|
||||
if (_windowChrome is not null) return;
|
||||
_windowChrome = new WindowChrome(this, header, RequestExit);
|
||||
_windowChrome.SetLoginMode(true);
|
||||
InitializeDashboardHeader(header);
|
||||
}
|
||||
|
||||
private void LayoutWindowChrome() => RefreshDashboardHeaderPresentation();
|
||||
|
||||
private void InitializeDashboardHeader(Panel header)
|
||||
{
|
||||
_dashboardHeaderName.Visible = _dashboardSettings.Visible = _dashboardAbout.Visible =
|
||||
_dashboardLogout.Visible = _dashboardMore.Visible = _dashboardClose.Visible = false;
|
||||
_dashboardSettings.TabIndex = 890;
|
||||
_dashboardAbout.TabIndex = 891;
|
||||
_dashboardLogout.TabIndex = 892;
|
||||
_dashboardMore.TabIndex = 890;
|
||||
_logoutButton.TabIndex = 892;
|
||||
_dashboardClose.TabIndex = 901;
|
||||
_dashboardSettings.Click += (_, _) => OpenDashboardMenu(_dashboardSettings, includeApplicationActions: false);
|
||||
_dashboardMore.Click += (_, _) => OpenDashboardMenu(_dashboardMore, includeApplicationActions: true);
|
||||
_dashboardAbout.Click += (_, _) => ShowDashboardAbout();
|
||||
_dashboardLogout.Click += async (_, _) => await LogoutAsync();
|
||||
_dashboardClose.Click += (_, _) =>
|
||||
{
|
||||
if (_settingsMenu?.Visible == true) { _settingsMenu.Close(); return; }
|
||||
if (_settingsDismissedAt != long.MinValue && Environment.TickCount64 - _settingsDismissedAt < 350) return;
|
||||
RequestExit();
|
||||
};
|
||||
var tip = new ToolTip();
|
||||
_welcomeLabel.TextChanged += (_, _) =>
|
||||
{
|
||||
_dashboardHeaderName.Text = _welcomeLabel.Text;
|
||||
tip.SetToolTip(_dashboardHeaderName, _welcomeLabel.Text);
|
||||
tip.SetToolTip(_welcomeLabel, _welcomeLabel.Text);
|
||||
};
|
||||
_logoutButton.EnabledChanged += (_, _) => _dashboardLogout.Enabled = _logoutButton.Enabled;
|
||||
_dashboardView.VisibleChanged += (_, _) =>
|
||||
{
|
||||
if (!Disposing && !IsDisposed) LayoutBrandHeader();
|
||||
};
|
||||
header.SizeChanged += (_, _) => RefreshDashboardHeaderPresentation();
|
||||
tip.SetToolTip(_dashboardClose, "断开并退出");
|
||||
tip.SetToolTip(_dashboardSettings, "打开调度、节点、代理模式及趋势范围设置");
|
||||
tip.SetToolTip(_dashboardMore, "设置与关于");
|
||||
header.Disposed += (_, _) => tip.Dispose();
|
||||
header.Controls.AddRange([_dashboardHeaderName, _dashboardSettings, _dashboardAbout,
|
||||
_dashboardLogout, _dashboardMore, _dashboardClose]);
|
||||
}
|
||||
|
||||
private void RefreshDashboardHeaderPresentation()
|
||||
{
|
||||
if (Disposing || IsDisposed || _windowChrome is not { } chrome || _brandHeader.IsDisposed) return;
|
||||
_content.HeaderArtworkOffset = _dashboardView.HeaderArtworkOffset = _brandHeader.Height;
|
||||
var wide = WideDashboardPresentation && _dashboardView.Visible;
|
||||
_dashboardHeaderName.Visible = _dashboardSettings.Visible = _dashboardAbout.Visible =
|
||||
_dashboardLogout.Visible = wide;
|
||||
_dashboardClose.Visible = chrome.DashboardCloseSlot = _dashboardView.Visible;
|
||||
chrome.LayoutButtons();
|
||||
_dashboardClose.Bounds = chrome.DashboardCloseBounds;
|
||||
_dashboardClose.BringToFront();
|
||||
if (!CompactPresentation) LayoutExpandedBrandBounds();
|
||||
if (!wide)
|
||||
{
|
||||
_headerPoem.Visible = !CompactPresentation && _brandHeader.Width >= ScaleLogical(780);
|
||||
LayoutCompactDashboardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
_dashboardMore.Visible = false;
|
||||
_headerPoem.Visible = false;
|
||||
var caption = chrome.MinimizeButton.Bounds;
|
||||
_dashboardClose.Bounds = chrome.DashboardCloseBounds;
|
||||
int S(int value) => ScaleLogical(value);
|
||||
int x = caption.Left - S(10);
|
||||
foreach (var (button, width) in new[] { (_dashboardLogout, 106), (_dashboardAbout, 76), (_dashboardSettings, 76) })
|
||||
{
|
||||
x -= S(width);
|
||||
button.Bounds = new Rectangle(x, caption.Top, S(width), caption.Height);
|
||||
x -= S(8);
|
||||
}
|
||||
var nameWidth = Math.Min(S(224), Math.Max(S(96), x - S(316)));
|
||||
_dashboardHeaderName.Bounds = new Rectangle(x - nameWidth, caption.Top, nameWidth, caption.Height);
|
||||
}
|
||||
|
||||
private void LayoutExpandedBrandBounds()
|
||||
{
|
||||
int S(int value) => ScaleLogical(value);
|
||||
foreach (Control control in _brandHeader.Controls)
|
||||
{
|
||||
if (control.Tag is not Rectangle) continue;
|
||||
if (control is PictureBox) control.Bounds = new Rectangle(S(24), S(9), S(64), S(68));
|
||||
else if (control is Label { Text: "纵横家" }) control.Bounds = new Rectangle(S(99), S(10), S(146), S(36));
|
||||
else control.Bounds = new Rectangle(S(101), S(47), S(210), S(24));
|
||||
}
|
||||
}
|
||||
|
||||
private void LayoutCompactDashboardActions()
|
||||
{
|
||||
var show = CompactPresentation && _dashboardView.Visible && _logoutButton.Parent == _brandHeader;
|
||||
_dashboardMore.Visible = show;
|
||||
if (!show) return;
|
||||
|
||||
int S(int value) => ScaleLogical(value);
|
||||
var caption = _windowChrome!.MinimizeButton.Bounds;
|
||||
var settingsLeft = caption.Left - S(38);
|
||||
_dashboardMore.Bounds = new Rectangle(settingsLeft, caption.Top, S(32), caption.Height);
|
||||
_logoutButton.Bounds = new Rectangle(settingsLeft - S(70), caption.Top, S(64), caption.Height);
|
||||
var nameWidth = Math.Clamp(_logoutButton.Left - S(191), S(70), S(110));
|
||||
_welcomeLabel.Bounds = new Rectangle(_logoutButton.Left - nameWidth - S(6), caption.Top, nameWidth, caption.Height);
|
||||
foreach (var label in _brandHeader.Controls.OfType<Label>())
|
||||
{
|
||||
if (label.Tag is not Rectangle) continue;
|
||||
label.Width = Math.Clamp(_welcomeLabel.Left - label.Left - S(6), S(80), S(180));
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowDashboardAbout() => MessageBox.Show(this,
|
||||
$"纵横家 v{GetDisplayVersion()}\n智能安全网络\n\n优创未来(UCVL)\n管理服务器 {PlatformBootstrapTransport.ManagementAddress}",
|
||||
"关于纵横家", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
private void OpenDashboardMenu(Control anchor, bool includeApplicationActions)
|
||||
{
|
||||
if (_exiting || _settingsMenu?.Visible == true) return;
|
||||
var menu = _settingsMenu = new ContextMenuStrip { BackColor = Brand.Surface, ForeColor = Brand.Text, ShowImageMargin = false };
|
||||
var options = menu.Items;
|
||||
if (includeApplicationActions)
|
||||
{
|
||||
menu.Items.Add("关于纵横家", null, (_, _) => ShowDashboardAbout());
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
}
|
||||
foreach (var (label, combo) in new[] { ("调度方式", _connectionModeCombo), ("工作节点", _manualNodeCombo),
|
||||
("代理模式", _routeCombo), ("流量趋势时间范围", _historyRangeCombo) })
|
||||
{
|
||||
var item = options.Add(label);
|
||||
item.Enabled = combo.Visible && combo.Enabled && combo.Items.Count > 0;
|
||||
item.Click += (_, _) => BeginInvoke(() =>
|
||||
{
|
||||
if (_exiting || !combo.Visible || !combo.Enabled) return;
|
||||
combo.Focus();
|
||||
combo.DroppedDown = true;
|
||||
});
|
||||
}
|
||||
menu.Closed += (_, args) =>
|
||||
{
|
||||
if (args.CloseReason == ToolStripDropDownCloseReason.AppClicked)
|
||||
_settingsDismissedAt = Environment.TickCount64;
|
||||
_settingsMenu = null;
|
||||
menu.Dispose();
|
||||
};
|
||||
menu.Show(anchor, new Point(anchor.Width, anchor.Height), ToolStripDropDownDirection.BelowLeft);
|
||||
}
|
||||
|
||||
private void RestoreFromTrayPresentation()
|
||||
{
|
||||
ShowInTaskbar = true;
|
||||
WindowState = FormWindowState.Normal;
|
||||
UpdateTaskbarPresentation();
|
||||
}
|
||||
|
||||
private void UpdateTaskbarPresentation()
|
||||
{
|
||||
if (_exitResourcesDisposed) return;
|
||||
_notifyIcon.Visible = ShouldShowTrayIcon(WindowState, _preview || _uiOnly || _exiting);
|
||||
}
|
||||
|
||||
internal static bool ShouldShowTrayIcon(FormWindowState state, bool suppressed) =>
|
||||
!suppressed;
|
||||
|
||||
internal bool MinimizedOnTaskbarForTest => WindowState == FormWindowState.Minimized && Visible && ShowInTaskbar && !_exiting;
|
||||
}
|
||||
|
||||
internal enum DashboardHeaderIcon { User, Settings, About, Logout, More, Close }
|
||||
|
||||
internal sealed class DashboardHeaderButton : Button
|
||||
{
|
||||
private readonly DashboardHeaderIcon _glyph;
|
||||
private bool _hovered;
|
||||
|
||||
internal DashboardHeaderButton(string text, DashboardHeaderIcon glyph)
|
||||
{
|
||||
_glyph = glyph;
|
||||
Text = text;
|
||||
AccessibleName = text;
|
||||
Font = Brand.Font(10f);
|
||||
Cursor = Cursors.Hand;
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
UseVisualStyleBackColor = false;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
|
||||
ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
|
||||
SetStyle(ControlStyles.Opaque, false);
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e) { _hovered = true; Invalidate(); base.OnMouseEnter(e); }
|
||||
protected override void OnMouseLeave(EventArgs e) { _hovered = false; Invalidate(); base.OnMouseLeave(e); }
|
||||
protected override void OnGotFocus(EventArgs e) { Invalidate(); base.OnGotFocus(e); }
|
||||
protected override void OnLostFocus(EventArgs e) { Invalidate(); base.OnLostFocus(e); }
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (Width < 8 || Height < 8) return;
|
||||
var g = e.Graphics;
|
||||
var s = DeviceDpi / 96f;
|
||||
int S(int value) => Math.Max(1, (int)Math.Round(value * s));
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
var close = _glyph == DashboardHeaderIcon.Close;
|
||||
if (!close || _hovered)
|
||||
{
|
||||
using var path = UiGeometry.RoundedRectangle(Rectangle.Inflate(ClientRectangle, -2, -2), S(10));
|
||||
using var fill = new SolidBrush(close ? Brand.Danger : _hovered
|
||||
? Color.FromArgb(237, 220, 239, 255) : Color.FromArgb(176, 242, 250, 255));
|
||||
g.FillPath(fill, path);
|
||||
if (!close)
|
||||
{
|
||||
using var border = new Pen(Color.FromArgb(177, 151, 189, 225), Math.Max(1, s));
|
||||
g.DrawPath(border, path);
|
||||
}
|
||||
}
|
||||
|
||||
var color = !Enabled ? Brand.Muted : close && _hovered ? Color.White : Brand.Navy;
|
||||
var flags = TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding;
|
||||
var iconSize = S(close ? 18 : 17);
|
||||
var hasText = Text.Length != 0;
|
||||
var textWidth = hasText ? TextRenderer.MeasureText(g, Text, Font, Size.Empty, flags).Width : 0;
|
||||
var gap = hasText ? S(5) : 0;
|
||||
var left = Math.Max(S(3), (Width - iconSize - gap - textWidth) / 2);
|
||||
DashboardHeaderDrawing.Paint(g, _glyph, new Rectangle(left, (Height - iconSize) / 2, iconSize, iconSize), color);
|
||||
if (hasText) TextRenderer.DrawText(g, Text, Font,
|
||||
new Rectangle(left + iconSize + gap, 0, Math.Max(1, Width - left - iconSize - gap - S(3)), Height),
|
||||
color, flags | TextFormatFlags.EndEllipsis);
|
||||
if (Focused && ShowFocusCues) ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(ClientRectangle, -5, -5));
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DashboardHeaderIdentity : Label
|
||||
{
|
||||
internal DashboardHeaderIdentity()
|
||||
{
|
||||
BackColor = Color.Transparent;
|
||||
ForeColor = Brand.Navy;
|
||||
Font = Brand.Font(11f, FontStyle.Bold);
|
||||
AccessibleName = "当前登录用户";
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
var iconSize = (int)Math.Round(18 * DeviceDpi / 96.0);
|
||||
var gap = (int)Math.Round(6 * DeviceDpi / 96.0);
|
||||
var flags = TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding;
|
||||
var textWidth = TextRenderer.MeasureText(e.Graphics, Text, Font, Size.Empty, flags).Width;
|
||||
var left = Math.Max(0, Width - iconSize - gap - textWidth - gap);
|
||||
DashboardHeaderDrawing.Paint(e.Graphics, DashboardHeaderIcon.User,
|
||||
new Rectangle(left, (Height - iconSize) / 2, iconSize, iconSize), ForeColor);
|
||||
var textLeft = left + iconSize + gap;
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, new Rectangle(textLeft, 0, Math.Max(1, Width - textLeft), Height),
|
||||
ForeColor, flags | TextFormatFlags.EndEllipsis);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class DashboardHeaderDrawing
|
||||
{
|
||||
internal static void Paint(Graphics g, DashboardHeaderIcon glyph, Rectangle bounds, Color color)
|
||||
{
|
||||
if (glyph == DashboardHeaderIcon.Settings)
|
||||
{
|
||||
DashboardDrawing.Icon(g, DashboardIcon.Settings, bounds, color);
|
||||
return;
|
||||
}
|
||||
var state = g.Save();
|
||||
try
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.TranslateTransform(bounds.Left, bounds.Top);
|
||||
g.ScaleTransform(bounds.Width / 24f, bounds.Height / 24f);
|
||||
using var pen = new Pen(color, 1.85f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round };
|
||||
switch (glyph)
|
||||
{
|
||||
case DashboardHeaderIcon.User:
|
||||
g.DrawEllipse(pen, 8, 2, 8, 8);
|
||||
g.DrawArc(pen, 3, 11, 18, 15, 180, 180);
|
||||
g.DrawLine(pen, 3, 18.5f, 21, 18.5f);
|
||||
break;
|
||||
case DashboardHeaderIcon.About:
|
||||
g.DrawEllipse(pen, 2, 2, 20, 20);
|
||||
g.DrawLine(pen, 12, 11, 12, 17);
|
||||
g.DrawLine(pen, 12, 7.5f, 12, 8);
|
||||
break;
|
||||
case DashboardHeaderIcon.Logout:
|
||||
g.DrawLines(pen, [new PointF(11, 3), new(3, 3), new(3, 21), new(11, 21)]);
|
||||
g.DrawLine(pen, 9, 12, 21, 12);
|
||||
g.DrawLines(pen, [new PointF(16, 7), new(21, 12), new(16, 17)]);
|
||||
break;
|
||||
case DashboardHeaderIcon.More:
|
||||
using (var dot = new SolidBrush(color))
|
||||
for (var x = 3; x <= 19; x += 8) g.FillEllipse(dot, x, 10.5f, 3.25f, 3.25f);
|
||||
break;
|
||||
case DashboardHeaderIcon.Close:
|
||||
g.DrawLine(pen, 5, 5, 19, 19);
|
||||
g.DrawLine(pen, 19, 5, 5, 19);
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally { g.Restore(state); }
|
||||
}
|
||||
}
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal sealed partial class MainForm
|
||||
{
|
||||
private WindowChrome? _windowChrome;
|
||||
private ContextMenuStrip? _settingsMenu;
|
||||
private readonly DashboardHeaderIdentity _dashboardHeaderName = new();
|
||||
private readonly DashboardHeaderButton _dashboardSettings = new("设置", DashboardHeaderIcon.Settings);
|
||||
private readonly DashboardHeaderButton _dashboardAbout = new("关于", DashboardHeaderIcon.About);
|
||||
private readonly DashboardHeaderButton _dashboardLogout = new("退出账号", DashboardHeaderIcon.Logout);
|
||||
private readonly DashboardHeaderButton _dashboardMore = new("", DashboardHeaderIcon.Settings)
|
||||
{ AccessibleName = "设置" };
|
||||
internal WindowChrome? WindowChromeForTest => _windowChrome;
|
||||
|
||||
// Remove the native caption before HWND creation, not only after its first
|
||||
// style/paint messages. This avoids a transient second caption at startup.
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
var parameters = base.CreateParams;
|
||||
parameters.Style = unchecked((int)ChromeNative.ClientChromeStyle(parameters.Style));
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
LayoutBrandHeader();
|
||||
CenterCards();
|
||||
LayoutDashboard();
|
||||
}
|
||||
|
||||
// Explicit title/tray Exit and installer IPC share the graceful exit path.
|
||||
private void InitializeWindowChrome(Panel header)
|
||||
{
|
||||
if (_windowChrome is not null) return;
|
||||
_windowChrome = new WindowChrome(this, header, RequestExit, MinimizeToTrayPresentation);
|
||||
_windowChrome.SetLoginMode(true);
|
||||
InitializeDashboardHeader(header);
|
||||
}
|
||||
|
||||
private void LayoutWindowChrome() => RefreshDashboardHeaderPresentation();
|
||||
|
||||
private void InitializeDashboardHeader(Panel header)
|
||||
{
|
||||
_dashboardHeaderName.Visible = _dashboardSettings.Visible = _dashboardAbout.Visible =
|
||||
_dashboardLogout.Visible = _dashboardMore.Visible = false;
|
||||
_dashboardSettings.TabIndex = 890;
|
||||
_dashboardAbout.TabIndex = 891;
|
||||
_dashboardLogout.TabIndex = 892;
|
||||
_dashboardMore.TabIndex = 890;
|
||||
_logoutButton.TabIndex = 892;
|
||||
_dashboardSettings.Click += (_, _) => OpenDashboardMenu(_dashboardSettings, includeApplicationActions: false);
|
||||
_dashboardMore.Click += (_, _) => OpenDashboardMenu(_dashboardMore, includeApplicationActions: true);
|
||||
_dashboardAbout.Click += (_, _) => ShowDashboardAbout();
|
||||
_dashboardLogout.Click += async (_, _) => await LogoutAsync();
|
||||
var tip = new ToolTip();
|
||||
_welcomeLabel.TextChanged += (_, _) =>
|
||||
{
|
||||
_dashboardHeaderName.Text = _welcomeLabel.Text;
|
||||
tip.SetToolTip(_dashboardHeaderName, _welcomeLabel.Text);
|
||||
tip.SetToolTip(_welcomeLabel, _welcomeLabel.Text);
|
||||
};
|
||||
_logoutButton.EnabledChanged += (_, _) => _dashboardLogout.Enabled = _logoutButton.Enabled;
|
||||
_dashboardView.VisibleChanged += (_, _) =>
|
||||
{
|
||||
if (!Disposing && !IsDisposed) LayoutBrandHeader();
|
||||
};
|
||||
header.SizeChanged += (_, _) => RefreshDashboardHeaderPresentation();
|
||||
tip.SetToolTip(_dashboardSettings, "打开调度、节点、代理模式及趋势范围设置");
|
||||
tip.SetToolTip(_dashboardMore, "设置与关于");
|
||||
header.Disposed += (_, _) =>
|
||||
{
|
||||
tip.Dispose();
|
||||
_settingsMenu?.Dispose();
|
||||
};
|
||||
header.Controls.AddRange([_dashboardHeaderName, _dashboardSettings, _dashboardAbout,
|
||||
_dashboardLogout, _dashboardMore]);
|
||||
}
|
||||
|
||||
private void RefreshDashboardHeaderPresentation()
|
||||
{
|
||||
if (Disposing || IsDisposed || _windowChrome is not { } chrome || _brandHeader.IsDisposed) return;
|
||||
_content.HeaderArtworkOffset = _dashboardView.HeaderArtworkOffset = _brandHeader.Height;
|
||||
var wide = WideDashboardPresentation && _dashboardView.Visible;
|
||||
_dashboardHeaderName.Visible = _dashboardSettings.Visible = _dashboardAbout.Visible =
|
||||
_dashboardLogout.Visible = wide;
|
||||
chrome.LayoutButtons();
|
||||
if (!CompactPresentation) LayoutExpandedBrandBounds();
|
||||
if (!wide)
|
||||
{
|
||||
_headerPoem.Visible = !CompactPresentation && _brandHeader.Width >= ScaleLogical(780);
|
||||
LayoutCompactDashboardActions();
|
||||
return;
|
||||
}
|
||||
|
||||
_dashboardMore.Visible = false;
|
||||
_headerPoem.Visible = false;
|
||||
var caption = chrome.MinimizeButton.Bounds;
|
||||
int S(int value) => ScaleLogical(value);
|
||||
int x = caption.Left - S(10);
|
||||
foreach (var (button, width) in new[] { (_dashboardLogout, 106), (_dashboardAbout, 76), (_dashboardSettings, 76) })
|
||||
{
|
||||
x -= S(width);
|
||||
button.Bounds = new Rectangle(x, caption.Top, S(width), caption.Height);
|
||||
x -= S(8);
|
||||
}
|
||||
var nameWidth = Math.Min(S(224), Math.Max(S(96), x - S(316)));
|
||||
_dashboardHeaderName.Bounds = new Rectangle(x - nameWidth, caption.Top, nameWidth, caption.Height);
|
||||
}
|
||||
|
||||
private void LayoutExpandedBrandBounds()
|
||||
{
|
||||
int S(int value) => ScaleLogical(value);
|
||||
foreach (Control control in _brandHeader.Controls)
|
||||
{
|
||||
if (control.Tag is not Rectangle) continue;
|
||||
if (control is PictureBox) control.Bounds = new Rectangle(S(24), S(9), S(64), S(68));
|
||||
else if (control is Label { Text: "纵横家" }) control.Bounds = new Rectangle(S(99), S(10), S(146), S(36));
|
||||
else control.Bounds = new Rectangle(S(101), S(47), S(210), S(24));
|
||||
}
|
||||
}
|
||||
|
||||
private void LayoutCompactDashboardActions()
|
||||
{
|
||||
var show = CompactPresentation && _dashboardView.Visible && _logoutButton.Parent == _brandHeader;
|
||||
_dashboardMore.Visible = show;
|
||||
_welcomeLabel.Visible = false;
|
||||
if (!show) return;
|
||||
|
||||
int S(int value) => ScaleLogical(value);
|
||||
var caption = _windowChrome!.MinimizeButton.Bounds;
|
||||
var settingsLeft = caption.Left - S(38);
|
||||
_dashboardMore.Bounds = new Rectangle(settingsLeft, caption.Top, S(32), caption.Height);
|
||||
_logoutButton.Bounds = new Rectangle(settingsLeft - S(70), caption.Top, S(64), caption.Height);
|
||||
}
|
||||
|
||||
private void ShowDashboardAbout() => MessageBox.Show(this,
|
||||
$"纵横家 v{GetDisplayVersion()}\n智能安全网络\n\n优创未来(UCVL)\n管理服务器 {PlatformBootstrapTransport.ManagementAddress}",
|
||||
"关于纵横家", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
private void OpenDashboardMenu(Control anchor, bool includeApplicationActions)
|
||||
{
|
||||
if (_exiting || _settingsMenu?.Visible == true) return;
|
||||
_settingsMenu?.Dispose();
|
||||
var menu = _settingsMenu = new ContextMenuStrip { BackColor = Brand.Surface, ForeColor = Brand.Text, ShowImageMargin = false };
|
||||
var options = menu.Items;
|
||||
if (includeApplicationActions)
|
||||
{
|
||||
var account = _accountLabel.Text;
|
||||
if (!string.IsNullOrWhiteSpace(account))
|
||||
{
|
||||
options.Add(new ToolStripLabel("当前账号 " + account));
|
||||
options.Add(new ToolStripSeparator());
|
||||
}
|
||||
menu.Items.Add("关于纵横家", null, (_, _) => ShowDashboardAbout());
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
}
|
||||
foreach (var (label, combo) in new[] { ("调度方式", _connectionModeCombo), ("工作节点", _manualNodeCombo),
|
||||
("代理模式", _routeCombo), ("流量趋势时间范围", _historyRangeCombo) })
|
||||
{
|
||||
var item = options.Add(label);
|
||||
item.Enabled = combo.Visible && combo.Enabled && combo.Items.Count > 0;
|
||||
item.Click += (_, _) => BeginInvoke(() =>
|
||||
{
|
||||
if (_exiting || !combo.Visible || !combo.Enabled) return;
|
||||
combo.Focus();
|
||||
combo.DroppedDown = true;
|
||||
});
|
||||
}
|
||||
menu.Show(anchor, new Point(anchor.Width, anchor.Height), ToolStripDropDownDirection.BelowLeft);
|
||||
}
|
||||
|
||||
private void MinimizeToTrayPresentation()
|
||||
{
|
||||
if (_exiting || IsDisposed || Disposing) return;
|
||||
UpdateTaskbarPresentation();
|
||||
Hide();
|
||||
ShowInTaskbar = false;
|
||||
}
|
||||
|
||||
private void RestoreFromTrayPresentation()
|
||||
{
|
||||
ShowInTaskbar = true;
|
||||
WindowState = FormWindowState.Normal;
|
||||
UpdateTaskbarPresentation();
|
||||
}
|
||||
|
||||
private void UpdateTaskbarPresentation()
|
||||
{
|
||||
if (_exitResourcesDisposed) return;
|
||||
_notifyIcon.Visible = ShouldShowTrayIcon(WindowState, _preview || _uiOnly || _exiting);
|
||||
}
|
||||
|
||||
internal static bool ShouldShowTrayIcon(FormWindowState state, bool suppressed) =>
|
||||
!suppressed;
|
||||
|
||||
internal bool MinimizedOnTaskbarForTest => WindowState == FormWindowState.Minimized && Visible && ShowInTaskbar && !_exiting;
|
||||
}
|
||||
|
||||
internal enum DashboardHeaderIcon { User, Settings, About, Logout, More }
|
||||
|
||||
internal sealed class DashboardHeaderButton : Button
|
||||
{
|
||||
private readonly DashboardHeaderIcon _glyph;
|
||||
private bool _hovered;
|
||||
|
||||
internal DashboardHeaderButton(string text, DashboardHeaderIcon glyph)
|
||||
{
|
||||
_glyph = glyph;
|
||||
Text = text;
|
||||
AccessibleName = text;
|
||||
Font = Brand.Font(10f);
|
||||
Cursor = Cursors.Hand;
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
FlatAppearance.BorderSize = 0;
|
||||
UseVisualStyleBackColor = false;
|
||||
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
|
||||
ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
|
||||
SetStyle(ControlStyles.Opaque, false);
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs e) { _hovered = true; Invalidate(); base.OnMouseEnter(e); }
|
||||
protected override void OnMouseLeave(EventArgs e) { _hovered = false; Invalidate(); base.OnMouseLeave(e); }
|
||||
protected override void OnGotFocus(EventArgs e) { Invalidate(); base.OnGotFocus(e); }
|
||||
protected override void OnLostFocus(EventArgs e) { Invalidate(); base.OnLostFocus(e); }
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (Width < 8 || Height < 8) return;
|
||||
var g = e.Graphics;
|
||||
var s = DeviceDpi / 96f;
|
||||
int S(int value) => Math.Max(1, (int)Math.Round(value * s));
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using var path = UiGeometry.RoundedRectangle(Rectangle.Inflate(ClientRectangle, -2, -2), S(10));
|
||||
using var fill = new SolidBrush(_hovered
|
||||
? Color.FromArgb(237, 220, 239, 255) : Color.FromArgb(176, 242, 250, 255));
|
||||
g.FillPath(fill, path);
|
||||
using var border = new Pen(Color.FromArgb(177, 151, 189, 225), Math.Max(1, s));
|
||||
g.DrawPath(border, path);
|
||||
|
||||
var color = Enabled ? Brand.Navy : Brand.Muted;
|
||||
var flags = TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding;
|
||||
var iconSize = S(17);
|
||||
var hasText = Text.Length != 0;
|
||||
var textWidth = hasText ? TextRenderer.MeasureText(g, Text, Font, Size.Empty, flags).Width : 0;
|
||||
var gap = hasText ? S(5) : 0;
|
||||
var left = Math.Max(S(3), (Width - iconSize - gap - textWidth) / 2);
|
||||
DashboardHeaderDrawing.Paint(g, _glyph, new Rectangle(left, (Height - iconSize) / 2, iconSize, iconSize), color);
|
||||
if (hasText) TextRenderer.DrawText(g, Text, Font,
|
||||
new Rectangle(left + iconSize + gap, 0, Math.Max(1, Width - left - iconSize - gap - S(3)), Height),
|
||||
color, flags | TextFormatFlags.EndEllipsis);
|
||||
if (Focused && ShowFocusCues) DashboardHeaderDrawing.Focus(g, ClientRectangle, DeviceDpi, color);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DashboardHeaderIdentity : Label
|
||||
{
|
||||
internal DashboardHeaderIdentity()
|
||||
{
|
||||
BackColor = Color.Transparent;
|
||||
ForeColor = Brand.Navy;
|
||||
Font = Brand.Font(11f, FontStyle.Bold);
|
||||
AccessibleName = "当前登录用户";
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
var iconSize = (int)Math.Round(18 * DeviceDpi / 96.0);
|
||||
var gap = (int)Math.Round(6 * DeviceDpi / 96.0);
|
||||
var flags = TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding;
|
||||
var textWidth = TextRenderer.MeasureText(e.Graphics, Text, Font, Size.Empty, flags).Width;
|
||||
var left = Math.Max(0, Width - iconSize - gap - textWidth - gap);
|
||||
DashboardHeaderDrawing.Paint(e.Graphics, DashboardHeaderIcon.User,
|
||||
new Rectangle(left, (Height - iconSize) / 2, iconSize, iconSize), ForeColor);
|
||||
var textLeft = left + iconSize + gap;
|
||||
TextRenderer.DrawText(e.Graphics, Text, Font, new Rectangle(textLeft, 0, Math.Max(1, Width - textLeft), Height),
|
||||
ForeColor, flags | TextFormatFlags.EndEllipsis);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class DashboardHeaderDrawing
|
||||
{
|
||||
internal static void Focus(Graphics graphics, Rectangle bounds, int dpi, Color color)
|
||||
{
|
||||
var scale = dpi / 96f;
|
||||
var inset = Math.Max(3, (int)Math.Round(4 * scale));
|
||||
var inner = Rectangle.Inflate(bounds, -inset, -inset);
|
||||
if (inner.Width <= 0 || inner.Height <= 0) return;
|
||||
using var path = UiGeometry.RoundedRectangle(inner, Math.Max(2, (int)Math.Round(5 * scale)));
|
||||
using var pen = new Pen(SystemInformation.HighContrast ? SystemColors.Highlight : color, Math.Max(1.25f, 1.4f * scale));
|
||||
graphics.DrawPath(pen, path);
|
||||
}
|
||||
|
||||
internal static void Paint(Graphics g, DashboardHeaderIcon glyph, Rectangle bounds, Color color)
|
||||
{
|
||||
if (glyph == DashboardHeaderIcon.Settings)
|
||||
{
|
||||
DashboardDrawing.Icon(g, DashboardIcon.Settings, bounds, color);
|
||||
return;
|
||||
}
|
||||
var state = g.Save();
|
||||
try
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.TranslateTransform(bounds.Left, bounds.Top);
|
||||
g.ScaleTransform(bounds.Width / 24f, bounds.Height / 24f);
|
||||
using var pen = new Pen(color, 1.85f) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round };
|
||||
switch (glyph)
|
||||
{
|
||||
case DashboardHeaderIcon.User:
|
||||
g.DrawEllipse(pen, 8, 2, 8, 8);
|
||||
g.DrawArc(pen, 3, 11, 18, 15, 180, 180);
|
||||
g.DrawLine(pen, 3, 18.5f, 21, 18.5f);
|
||||
break;
|
||||
case DashboardHeaderIcon.About:
|
||||
g.DrawEllipse(pen, 2, 2, 20, 20);
|
||||
g.DrawLine(pen, 12, 11, 12, 17);
|
||||
g.DrawLine(pen, 12, 7.5f, 12, 8);
|
||||
break;
|
||||
case DashboardHeaderIcon.Logout:
|
||||
g.DrawLines(pen, [new PointF(11, 3), new(3, 3), new(3, 21), new(11, 21)]);
|
||||
g.DrawLine(pen, 9, 12, 21, 12);
|
||||
g.DrawLines(pen, [new PointF(16, 7), new(21, 12), new(16, 17)]);
|
||||
break;
|
||||
case DashboardHeaderIcon.More:
|
||||
using (var dot = new SolidBrush(color))
|
||||
for (var x = 3; x <= 19; x += 8) g.FillEllipse(dot, x, 10.5f, 3.25f, 3.25f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally { g.Restore(state); }
|
||||
}
|
||||
}
|
||||
|
||||
+30
-21
@@ -6,8 +6,8 @@ internal sealed partial class MainForm
|
||||
private bool WideDashboardPresentation => ClientSize.Width >= ScaleLogical(840) && ClientSize.Height >= ScaleLogical(480);
|
||||
private bool CompactPresentation => !WideDashboardPresentation;
|
||||
private readonly Font _compactStatusFont=Brand.Font(9.5f,FontStyle.Bold);
|
||||
private readonly Font _wideStatusFont=Brand.Font(20f,FontStyle.Bold);
|
||||
private readonly Font _denseStatusFont=Brand.Font(16f,FontStyle.Bold);
|
||||
private readonly Font _wideStatusFont=Brand.Font(17f,FontStyle.Bold);
|
||||
private readonly Font _denseStatusFont=Brand.Font(15f,FontStyle.Bold);
|
||||
private readonly Font _wideChartFont=Brand.Font(9f);
|
||||
private readonly Font _compactChartFont=Brand.Font(7.5f);
|
||||
private readonly Font _compactFieldFont=Brand.Font(7.5f, FontStyle.Bold);
|
||||
@@ -80,7 +80,7 @@ internal sealed partial class MainForm
|
||||
LayoutWindowChrome();
|
||||
if (_welcomeLabel.Parent == _brandHeader)
|
||||
{
|
||||
_welcomeLabel.Visible=_dashboardView.Visible;
|
||||
_welcomeLabel.Visible=false;
|
||||
_logoutButton.Visible=_dashboardView.Visible;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,8 @@ internal sealed partial class MainForm
|
||||
{
|
||||
_welcomeLabel.Parent=_brandHeader;
|
||||
_logoutButton.Parent=_brandHeader;
|
||||
_welcomeLabel.Visible=_logoutButton.Visible=_dashboardView.Visible;
|
||||
_welcomeLabel.Visible=false;
|
||||
_logoutButton.Visible=_dashboardView.Visible;
|
||||
LayoutCompactDashboardActions();
|
||||
_accountLabel.Visible=_identityBadge.Visible=false;
|
||||
}
|
||||
@@ -141,19 +142,19 @@ internal sealed partial class MainForm
|
||||
_nodeIcon.Visible=_modeIcon.Visible=false;
|
||||
_scheduleBadge.Visible=false;
|
||||
var leftWidth=_modeCard.Left-S(8);
|
||||
_selectionHeading.Bounds=R(10,1,34,20);
|
||||
_routeHeading.Bounds=R(10,23,34,20);
|
||||
_selectionHeading.Bounds=R(10,2,34,20);
|
||||
_routeHeading.Bounds=R(10,22,34,20);
|
||||
_routeHeading.Text="模式";
|
||||
var fieldLeft=S(46); var fieldWidth=leftWidth-fieldLeft;
|
||||
var fieldLeft=S(44); var fieldWidth=leftWidth-fieldLeft;
|
||||
var splitWidth=Math.Max(S(84),(fieldWidth-S(4))/2);
|
||||
_connectionModeCombo.Bounds=new(fieldLeft,S(1),_manualNodeCombo.Visible?splitWidth:fieldWidth,S(20));
|
||||
_manualNodeCombo.Bounds=new(_connectionModeCombo.Right+S(4),S(1),Math.Max(S(60),fieldWidth-splitWidth-S(4)),S(20));
|
||||
_routeCombo.Bounds=new(fieldLeft,S(23),fieldWidth,S(20));
|
||||
_connectionModeCombo.Bounds=new(fieldLeft,S(2),_manualNodeCombo.Visible?splitWidth:fieldWidth,S(20));
|
||||
_manualNodeCombo.Bounds=new(_connectionModeCombo.Right+S(4),S(2),Math.Max(S(60),fieldWidth-splitWidth-S(4)),S(20));
|
||||
_routeCombo.Bounds=new(fieldLeft,S(22),fieldWidth,S(20));
|
||||
_nodeHeading.Text="节点";
|
||||
_nodeHeading.Bounds=R(8,1,34,20);
|
||||
_currentNodeLabel.Bounds=new(S(44),S(1),_modeCard.Width-S(46),S(20));
|
||||
_actualModeHeading.Bounds=R(8,23,34,20);
|
||||
_routeReadOnly.Bounds=new(S(44),S(23),_modeCard.Width-S(46),S(20));
|
||||
_nodeHeading.Bounds=R(10,2,34,20);
|
||||
_currentNodeLabel.Bounds=new(fieldLeft,S(2),_modeCard.Width-fieldLeft-S(2),S(20));
|
||||
_actualModeHeading.Bounds=R(10,22,34,20);
|
||||
_routeReadOnly.Bounds=new(fieldLeft,S(22),_modeCard.Width-fieldLeft-S(2),S(20));
|
||||
foreach(var label in new[]{_selectionHeading,_routeHeading,_nodeHeading,_actualModeHeading,_currentNodeLabel})
|
||||
{ label.TextAlign=ContentAlignment.MiddleLeft; label.Padding=Padding.Empty; }
|
||||
_selectionHeading.Font = _routeHeading.Font = _nodeHeading.Font = _actualModeHeading.Font = _compactFieldFont;
|
||||
@@ -170,17 +171,25 @@ internal sealed partial class MainForm
|
||||
_tailnetUploadMetric.Bounds=_uploadMetric.Bounds;
|
||||
_tailnetDownloadMetric.Bounds=_downloadMetric.Bounds;
|
||||
}
|
||||
_trendHeading.Text="本机代理趋势 · "+(_selectionUiConnected?(_currentNodeUsesTailnet?"Tailscale":"公网入口"):"未连接");
|
||||
_trendHeading.Bounds=new(S(10),S(2),_speedTrendCard.Width-S(120),S(18));
|
||||
_trendHeading.Text = !_selectionUiConnected ? "本机代理趋势" :
|
||||
_currentNodeUsesTailnet ? "代理趋势 · Tailscale" : "代理趋势 · 公网入口";
|
||||
var headerTop = S(2);
|
||||
var headerHeight = S(20);
|
||||
var inset = S(10);
|
||||
var headingWidth = S(116);
|
||||
var rangeWidth = S(78);
|
||||
var rangeLeft = _speedTrendCard.Width - rangeWidth - inset;
|
||||
_trendHeading.Bounds = new(inset, headerTop, headingWidth, headerHeight);
|
||||
_trendHeading.TextAlign=ContentAlignment.MiddleLeft;
|
||||
_historyRangeCombo.Bounds=new(_speedTrendCard.Width-S(98),S(2),S(88),S(18));
|
||||
var legendWidth = Math.Max(S(90), (_speedTrendCard.Width - S(118)) / 2);
|
||||
_uploadLegend.Bounds=new(S(10),S(20),legendWidth,S(16));
|
||||
_downloadLegend.Bounds=new(_uploadLegend.Right,S(20),legendWidth,S(16));
|
||||
_historyRangeCombo.Bounds = new(rangeLeft, headerTop, rangeWidth, headerHeight);
|
||||
var legendLeft = _trendHeading.Right + S(4);
|
||||
var legendWidth = Math.Max(1, (rangeLeft - S(5) - legendLeft) / 2);
|
||||
_uploadLegend.Bounds = new(legendLeft, headerTop, legendWidth, headerHeight);
|
||||
_downloadLegend.Bounds = new(_uploadLegend.Right, headerTop, legendWidth, headerHeight);
|
||||
_uploadLegend.TextAlign=_downloadLegend.TextAlign=ContentAlignment.MiddleLeft;
|
||||
_uploadLegend.Visible=_downloadLegend.Visible=true;
|
||||
_trafficChart.Font=_compactChartFont;
|
||||
_trafficChart.Bounds=new(S(8),S(36),_speedTrendCard.Width-S(16),Math.Max(S(22),_speedTrendCard.Height-S(40)));
|
||||
_trafficChart.Bounds = new(S(8), S(23), _speedTrendCard.Width - S(16), Math.Max(1, _speedTrendCard.Height - S(27)));
|
||||
_historyStatus.Visible=false;
|
||||
_sampleLabel.Visible=false;
|
||||
_planLabel.Visible=false;
|
||||
|
||||
@@ -96,7 +96,7 @@ internal sealed partial class MainForm
|
||||
_modeCard.Paint += (_, e) =>
|
||||
{
|
||||
using var divider = new Pen(Color.FromArgb(130, 160, 189, 211), Math.Max(1, DeviceDpi / 96f * .6f));
|
||||
var x = WideDashboardPresentation ? _modeIcon.Left - ScaleLogical(7) : 0;
|
||||
const int x = 0;
|
||||
e.Graphics.DrawLine(divider, x, ScaleLogical(8), x, _modeCard.Height - ScaleLogical(8));
|
||||
};
|
||||
BuildConnectionSelection();
|
||||
@@ -377,7 +377,7 @@ internal sealed partial class MainForm
|
||||
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, _wideMonitor, _wideSummary }
|
||||
private bool DashboardControlsFit() => new Control[] { _statusCard, _nodeCard, _modeCard, _trafficCard, _tailnetTrafficCard, _speedTrendCard, _dailyCard, _footer, _wideMonitor }
|
||||
.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));
|
||||
}
|
||||
|
||||
@@ -1,44 +1,24 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal sealed partial class MainForm
|
||||
{
|
||||
private readonly CardPanel _wideMonitor = new() { Visible = false };
|
||||
private readonly TrendSummaryPanel _wideSummary = new() { Visible = false };
|
||||
private readonly Label _wideSummaryState = new(), _wideSidebarPlan = new(), _wideFooterState = new();
|
||||
private readonly DashboardGlyph _wideFooterClock = new(DashboardIcon.History);
|
||||
private readonly DashboardGlyph _wideFooterShield = new(DashboardIcon.Shield);
|
||||
private readonly CardPanel _wideMonitor = new() { Visible = false, Embedded = true };
|
||||
private readonly Label _wideSummaryState = new();
|
||||
private readonly RoundedButton _wideUpload = new(), _wideDownload = new();
|
||||
private readonly DashboardFeature[] _wideFeatures =
|
||||
[
|
||||
new(DashboardIcon.Server, "线路调度", "自动分配或手动选择"),
|
||||
new(DashboardIcon.Shield, "入口验证", "Tailscale 与青岛公网", true),
|
||||
new(DashboardIcon.Layers, "灵活代理", "以已生效的模式为准", true),
|
||||
];
|
||||
private bool _wideDashboardBuilt;
|
||||
private TrafficChartSeries _wideSeries = TrafficChartSeries.Upload;
|
||||
private TrafficChartSeries _wideSeries = TrafficChartSeries.Both;
|
||||
|
||||
private void BuildWideDashboard()
|
||||
{
|
||||
_wideMonitor.AccessibleName = "连接状态和流量监控";
|
||||
_dashboardBody.Controls.Add(_wideMonitor);
|
||||
ConfigureLabel(_wideSummaryState, "", Brand.Font(10, FontStyle.Bold), Brand.Text);
|
||||
ConfigureLabel(_wideSidebarPlan, "", Brand.Font(8), Brand.Muted);
|
||||
ConfigureLabel(_wideFooterState, "", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
||||
foreach (var label in new[] { _wideSummaryState, _wideSidebarPlan, _wideFooterState })
|
||||
{
|
||||
label.AutoEllipsis = true;
|
||||
label.TextAlign = ContentAlignment.MiddleLeft;
|
||||
}
|
||||
_wideSummary.Controls.Add(_wideSummaryState);
|
||||
_nodeCard.Controls.Add(_wideSummary);
|
||||
_nodeCard.Controls.Add(_wideSidebarPlan);
|
||||
_nodeCard.Controls.AddRange(_wideFeatures);
|
||||
ConfigureLabel(_wideSummaryState, "", Brand.Font(8, FontStyle.Bold), Brand.Muted);
|
||||
_wideSummaryState.AutoEllipsis = true;
|
||||
_wideSummaryState.TextAlign = ContentAlignment.MiddleRight;
|
||||
_modeCard.Controls.Add(_wideSummaryState);
|
||||
_connectionModeCombo.LeadingIcon = DashboardIcon.Settings;
|
||||
_routeCombo.LeadingIcon = DashboardIcon.Layers;
|
||||
_manualNodeCombo.LeadingIcon = DashboardIcon.Server;
|
||||
_footer.Controls.AddRange([_wideFooterClock, _wideFooterShield, _wideFooterState]);
|
||||
_modeCard.Controls.AddRange([_nodeIcon, _modeIcon]);
|
||||
ConfigureSecondaryButton(_wideUpload, "↑ 上传 —", Point.Empty, new(144, 29));
|
||||
ConfigureSecondaryButton(_wideDownload, "↓ 下载 —", Point.Empty, new(144, 29));
|
||||
@@ -53,20 +33,20 @@ internal sealed partial class MainForm
|
||||
|
||||
private void SelectWideTrafficSeries(TrafficChartSeries series)
|
||||
{
|
||||
_wideSeries = series;
|
||||
_wideSeries = _wideSeries == series ? TrafficChartSeries.Both : series;
|
||||
ApplyWideTrafficSeries(WideDashboardPresentation);
|
||||
}
|
||||
|
||||
private void ApplyWideTrafficSeries(bool wide)
|
||||
{
|
||||
_trafficChart.DisplayedSeries = wide ? _wideSeries : TrafficChartSeries.Both;
|
||||
UpdateTab(_wideUpload, _wideSeries == TrafficChartSeries.Upload);
|
||||
UpdateTab(_wideDownload, _wideSeries == TrafficChartSeries.Download);
|
||||
static void UpdateTab(RoundedButton button, bool selected)
|
||||
UpdateTab(_wideUpload, Brand.RoyalBlue, _wideSeries != TrafficChartSeries.Download);
|
||||
UpdateTab(_wideDownload, TrafficChart.DownloadColor, _wideSeries != TrafficChartSeries.Upload);
|
||||
static void UpdateTab(RoundedButton button, Color accent, bool visible)
|
||||
{
|
||||
button.BackColor = selected ? Brand.RoyalBlue : Color.White;
|
||||
button.ForeColor = selected ? Color.White : Brand.DeepBlue;
|
||||
button.AccessibleDescription = selected ? "当前显示" : "点击切换";
|
||||
button.BackColor = Color.White;
|
||||
button.ForeColor = visible ? accent : Brand.Muted;
|
||||
button.AccessibleDescription = visible ? "曲线可见,点击切换" : "曲线已隐藏,点击显示";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,31 +57,20 @@ internal sealed partial class MainForm
|
||||
{
|
||||
if (!ReferenceEquals(control.Parent, parent)) control.Parent = parent;
|
||||
}
|
||||
Move(_modeCard, wide ? _wideMonitor : _nodeCard);
|
||||
Move(_speedTrendCard, wide ? _wideMonitor : _dashboardBody);
|
||||
Move(_dailyCard, wide ? _wideMonitor : _dashboardBody);
|
||||
Move(_nodeTrafficPanel, wide ? _wideMonitor : _dashboardBody);
|
||||
Move(_trendHeading, wide ? _wideSummary : _speedTrendCard);
|
||||
var rangeParent = wide ? _modeCard : _speedTrendCard;
|
||||
if (_historyRangeCombo.Parent != rangeParent)
|
||||
{
|
||||
_historyRangeCombo.DroppedDown = false;
|
||||
Move(_historyRangeCombo, rangeParent);
|
||||
}
|
||||
_wideMonitor.Visible = wide;
|
||||
_wideSummary.Visible = _wideSidebarPlan.Visible = wide;
|
||||
_wideSummaryState.Visible = wide;
|
||||
_wideUpload.Visible = _wideDownload.Visible = wide;
|
||||
_wideFooterClock.Visible = _wideFooterShield.Visible = _wideFooterState.Visible = wide;
|
||||
_footerCompanySite.Visible = !wide;
|
||||
_dailyIcon.Visible = wide;
|
||||
foreach (var feature in _wideFeatures) feature.Visible = wide;
|
||||
_usageMetric.InlineTotal = _sessionMetric.InlineTotal = wide;
|
||||
_statusCard.WideBanner = wide;
|
||||
_statusCard.WideBanner = false;
|
||||
_connectButton.Capsule = wide;
|
||||
_nodeCard.GlassRim = _wideMonitor.GlassRim = _wideSummary.GlassRim
|
||||
= _speedTrendCard.GlassRim = _dailyCard.GlassRim = _footer.GlassRim = wide;
|
||||
_nodeCard.GlassRim = _speedTrendCard.GlassRim = _dailyCard.GlassRim = _footer.GlassRim = wide;
|
||||
_uploadLegend.Visible = _downloadLegend.Visible = !wide;
|
||||
_historyStatus.Visible = wide;
|
||||
_historyStatus.Visible = false;
|
||||
ApplyWideTrafficSeries(wide);
|
||||
RefreshConnectionAppearance();
|
||||
}
|
||||
@@ -110,13 +79,13 @@ internal sealed partial class MainForm
|
||||
{
|
||||
int S(int value) => ScaleLogical(value);
|
||||
var dense = viewport.Height < S(465);
|
||||
var layout = DashboardWideLayout.Calculate(viewport, DeviceDpi, _canViewNodeTraffic);
|
||||
var layout = DashboardWideLayout.Calculate(viewport, DeviceDpi, _canViewNodeTraffic, _manualNodeCombo.Visible);
|
||||
_dashboardBody.Bounds = new Rectangle(Point.Empty, viewport);
|
||||
if (_welcomeLabel.Parent != _dashboardBody) _welcomeLabel.Parent = _dashboardBody;
|
||||
if (_logoutButton.Parent != _dashboardBody) _logoutButton.Parent = _dashboardBody;
|
||||
_welcomeLabel.Visible = _logoutButton.Visible = _accountLabel.Visible = _identityBadge.Visible = false;
|
||||
_statusCard.Bounds = layout.Banner;
|
||||
_nodeCard.Bounds = layout.Sidebar;
|
||||
_nodeCard.Bounds = layout.Configuration;
|
||||
_wideMonitor.Bounds = layout.Monitor;
|
||||
_modeCard.Bounds = layout.State;
|
||||
_speedTrendCard.Bounds = layout.Trend;
|
||||
@@ -127,114 +96,85 @@ internal sealed partial class MainForm
|
||||
_tailnetSampleLabel.Visible = false;
|
||||
|
||||
var bannerHeight = _statusCard.Height;
|
||||
var actionWidth = S(dense ? 132 : 158);
|
||||
var actionHeight = S(dense ? 36 : 42);
|
||||
var shieldSize = S(dense ? 43 : 52);
|
||||
_statusDot.Bounds = new Rectangle(S(22), (bannerHeight - shieldSize) / 2, shieldSize, shieldSize);
|
||||
_connectButton.Bounds = new Rectangle(_statusCard.Width - actionWidth - S(22), (bannerHeight - actionHeight) / 2, actionWidth, actionHeight);
|
||||
var statusLeft = S(dense ? 77 : 90);
|
||||
var statusWidth = _connectButton.Left - statusLeft - S(13);
|
||||
_statusTitle.Bounds = new Rectangle(statusLeft, bannerHeight / 2 - S(dense ? 24 : 30), statusWidth, S(dense ? 26 : 33));
|
||||
_statusDetail.Bounds = new Rectangle(statusLeft + S(2), bannerHeight / 2 + S(dense ? 1 : 4), statusWidth, S(dense ? 20 : 23));
|
||||
var actionWidth = S(dense ? 120 : 138);
|
||||
var actionHeight = S(dense ? 34 : 38);
|
||||
var shieldSize = S(dense ? 36 : 42);
|
||||
var pad = S(dense ? 14 : 18);
|
||||
_statusDot.Bounds = new Rectangle(pad, (bannerHeight - shieldSize) / 2, shieldSize, shieldSize);
|
||||
_connectButton.Bounds = new Rectangle(_statusCard.Width - actionWidth - pad, (bannerHeight - actionHeight) / 2, actionWidth, actionHeight);
|
||||
var statusLeft = _statusDot.Right + S(12);
|
||||
var statusWidth = _connectButton.Left - statusLeft - S(12);
|
||||
_statusTitle.Bounds = new Rectangle(statusLeft, bannerHeight / 2 - S(dense ? 22 : 26), statusWidth, S(dense ? 25 : 29));
|
||||
_statusDetail.Bounds = new Rectangle(statusLeft, bannerHeight / 2 + S(2), statusWidth, S(20));
|
||||
|
||||
var sidebarWidth = _nodeCard.Width;
|
||||
var selectorWidth = sidebarWidth - S(75);
|
||||
var firstRow = S(dense ? 9 : 15);
|
||||
var rowStep = S(dense ? 33 : 40);
|
||||
var rowHeight = S(dense ? 28 : 32);
|
||||
_selectionHeading.Bounds = new Rectangle(S(15), firstRow, S(47), rowHeight);
|
||||
_routeHeading.Bounds = new Rectangle(S(15), firstRow + rowStep, S(47), rowHeight);
|
||||
var rowHeight = S(dense ? 26 : 31);
|
||||
var fieldHeight = rowHeight - S(3);
|
||||
var firstRow = layout.State.Top;
|
||||
var valueLeft = pad + S(43);
|
||||
var fieldWidth = layout.State.Left - valueLeft - S(16);
|
||||
_selectionHeading.Bounds = new Rectangle(pad, firstRow, S(39), fieldHeight);
|
||||
_routeHeading.Bounds = new Rectangle(pad, firstRow + rowHeight, S(39), fieldHeight);
|
||||
_routeHeading.Text = "模式";
|
||||
_selectionHeading.TextAlign = _routeHeading.TextAlign = ContentAlignment.MiddleLeft;
|
||||
_connectionModeCombo.Bounds = new Rectangle(S(60), firstRow, selectorWidth, rowHeight);
|
||||
_routeCombo.Bounds = new Rectangle(S(60), firstRow + rowStep, selectorWidth, rowHeight);
|
||||
_manualNodeCombo.Bounds = new Rectangle(S(60), firstRow + 2 * rowStep, selectorWidth, S(29));
|
||||
var summaryTop = firstRow + (_manualNodeCombo.Visible ? 3 : 2) * rowStep + S(3);
|
||||
var remaining = _nodeCard.Height - summaryTop - S(24);
|
||||
var summaryHeight = Math.Clamp(remaining / 3, S(dense ? 55 : 65), S(115));
|
||||
_wideSummary.Bounds = new Rectangle(S(10), summaryTop, sidebarWidth - S(20), summaryHeight);
|
||||
_trendHeading.Text = "本机代理趋势";
|
||||
_trendHeading.Bounds = new Rectangle(S(13), S(8), _wideSummary.Width - S(26), S(22));
|
||||
_trendHeading.TextAlign = ContentAlignment.MiddleLeft;
|
||||
_wideSummaryState.Bounds = new Rectangle(S(13), S(31), _wideSummary.Width - S(26), S(22));
|
||||
_wideSidebarPlan.Bounds = new Rectangle(S(14), _nodeCard.Height - S(25), sidebarWidth - S(28), S(16));
|
||||
var featureTop = _wideSummary.Bottom + S(5);
|
||||
var featureHeight = Math.Min(S(66), (_wideSidebarPlan.Top - featureTop - S(4)) / _wideFeatures.Length);
|
||||
for (var index = 0; index < _wideFeatures.Length; index++)
|
||||
{
|
||||
var feature = _wideFeatures[index];
|
||||
feature.Visible = featureHeight >= S(30);
|
||||
if (feature.Visible) feature.Bounds = new Rectangle(S(12), featureTop + index * featureHeight, sidebarWidth - S(24), featureHeight);
|
||||
}
|
||||
_connectionModeCombo.Bounds = new Rectangle(valueLeft, firstRow, fieldWidth, fieldHeight);
|
||||
_routeCombo.Bounds = new Rectangle(valueLeft, firstRow + rowHeight, fieldWidth, fieldHeight);
|
||||
_manualNodeCombo.Bounds = new Rectangle(valueLeft, firstRow + 2 * rowHeight, fieldWidth, fieldHeight);
|
||||
|
||||
var stateHeight = _modeCard.Height;
|
||||
var rangeWidth = S(129);
|
||||
var statesWidth = _modeCard.Width - rangeWidth - S(23);
|
||||
using var metrics = _modeCard.CreateGraphics();
|
||||
int TextWidth(string text, Font font) => TextRenderer.MeasureText(metrics, text, font,
|
||||
Size.Empty, TextFormatFlags.SingleLine).Width;
|
||||
var headingLeft = S(34);
|
||||
var headingWidth = Math.Max(S(40), Math.Max(TextWidth("节点", _nodeHeading.Font),
|
||||
TextWidth("模式", _actualModeHeading.Font)) + S(2));
|
||||
var valueInset = headingLeft + headingWidth;
|
||||
var modeWidth = Math.Clamp(TextWidth(_routeReadOnly.Text, _routeReadOnly.Font) + S(6), S(79), S(146));
|
||||
var splitLimit = Math.Max(valueInset + S(35), statesWidth - valueInset - modeWidth);
|
||||
var nodeRoom = splitLimit - valueInset - S(4);
|
||||
var nodeText = _selectionUiConnected && !string.IsNullOrWhiteSpace(_currentNodeName) ? _currentNodeName : _currentNodeLabel.Text;
|
||||
var nodeFont = _currentNodeLabel.Font;
|
||||
if (TextWidth(nodeText, nodeFont) > nodeRoom)
|
||||
{
|
||||
// The sidebar already identifies the active transport. Omit its
|
||||
// duplicate suffix here if it would crowd out the actual name.
|
||||
if (_selectionUiConnected && _currentNodeUsesTailnet && !string.IsNullOrWhiteSpace(_currentNodeBaseName))
|
||||
nodeText = _currentNodeBaseName;
|
||||
if (TextWidth(nodeText, nodeFont) > nodeRoom)
|
||||
nodeFont = TextWidth(nodeText, _narrowNodeFont) <= nodeRoom ? _narrowNodeFont : _minimumNodeFont;
|
||||
}
|
||||
_currentNodeLabel.Text = nodeText;
|
||||
_currentNodeLabel.Font = nodeFont;
|
||||
var split = Math.Min(splitLimit, Math.Max(statesWidth / 2, valueInset + TextWidth(nodeText, nodeFont) + S(4)));
|
||||
_historyRangeCombo.Bounds = new Rectangle(_modeCard.Width - rangeWidth - S(6), (stateHeight - S(31)) / 2, rangeWidth, S(31));
|
||||
_nodeIcon.Bounds = new Rectangle(S(7), (stateHeight - S(26)) / 2, S(26), S(26));
|
||||
var headingLeft = S(12);
|
||||
var headingWidth = S(45);
|
||||
var stateValueLeft = headingLeft + headingWidth;
|
||||
var entryWidth = _selectionUiConnected ? S(105) : 0;
|
||||
var stateWidth = _modeCard.Width - stateValueLeft - S(8);
|
||||
_nodeHeading.Text = "节点";
|
||||
_nodeHeading.Bounds = new Rectangle(headingLeft, 0, headingWidth, stateHeight);
|
||||
_currentNodeLabel.Bounds = new Rectangle(valueInset, 0, Math.Max(S(31), split - valueInset - S(4)), stateHeight);
|
||||
_modeIcon.Bounds = new Rectangle(split + S(7), (stateHeight - S(25)) / 2, S(25), S(25));
|
||||
_actualModeHeading.Bounds = new Rectangle(split + headingLeft, 0, headingWidth, stateHeight);
|
||||
_routeReadOnly.Bounds = new Rectangle(split + valueInset, 0, Math.Max(S(35), statesWidth - split - valueInset), stateHeight);
|
||||
_nodeIcon.Visible = _modeIcon.Visible = true;
|
||||
_nodeHeading.Bounds = new Rectangle(headingLeft, 0, headingWidth, fieldHeight);
|
||||
_currentNodeLabel.Bounds = new Rectangle(stateValueLeft, 0, stateWidth - entryWidth, fieldHeight);
|
||||
_actualModeHeading.Bounds = new Rectangle(headingLeft, rowHeight, headingWidth, fieldHeight);
|
||||
_routeReadOnly.Bounds = new Rectangle(stateValueLeft, rowHeight, stateWidth, fieldHeight);
|
||||
_wideSummaryState.Bounds = new Rectangle(_modeCard.Width - entryWidth - S(8), 0, entryWidth, fieldHeight);
|
||||
_wideSummaryState.Visible = _selectionUiConnected;
|
||||
if (_selectionUiConnected && !string.IsNullOrWhiteSpace(_currentNodeBaseName))
|
||||
_currentNodeLabel.Text = _currentNodeBaseName;
|
||||
using (var metrics = _modeCard.CreateGraphics())
|
||||
{
|
||||
int NodeWidth(Font font) => TextRenderer.MeasureText(metrics, _currentNodeLabel.Text, font,
|
||||
Size.Empty, TextFormatFlags.SingleLine).Width;
|
||||
if (NodeWidth(_currentNodeLabel.Font) > _currentNodeLabel.Width)
|
||||
_currentNodeLabel.Font = NodeWidth(_narrowNodeFont) <= _currentNodeLabel.Width ? _narrowNodeFont : _minimumNodeFont;
|
||||
}
|
||||
_nodeIcon.Visible = _modeIcon.Visible = false;
|
||||
_nodeHeading.TextAlign = _actualModeHeading.TextAlign = ContentAlignment.MiddleLeft;
|
||||
|
||||
var trendWidth = _speedTrendCard.Width;
|
||||
var tabWidth = Math.Min(S(164), (trendWidth - S(30)) / 2);
|
||||
var tabTop = S(dense ? 6 : 9);
|
||||
var tabHeight = S(dense ? 26 : 31);
|
||||
_wideUpload.Bounds = new Rectangle(S(12), tabTop, tabWidth, tabHeight);
|
||||
_wideDownload.Bounds = new Rectangle(_wideUpload.Right + S(4), tabTop, tabWidth, tabHeight);
|
||||
_historyStatus.Bounds = new Rectangle(_wideDownload.Right + S(6), tabTop, Math.Max(1, trendWidth - _wideDownload.Right - S(18)), tabHeight);
|
||||
_historyStatus.Text = "实时代理采样";
|
||||
var tabTop = S(7);
|
||||
var tabHeight = S(dense ? 24 : 28);
|
||||
var rangeWidth = S(128);
|
||||
var tabWidth = S(135);
|
||||
_historyRangeCombo.Bounds = new Rectangle(trendWidth - pad - rangeWidth, tabTop, rangeWidth, tabHeight);
|
||||
_wideDownload.Bounds = new Rectangle(_historyRangeCombo.Left - S(14) - tabWidth, tabTop, tabWidth, tabHeight);
|
||||
_wideUpload.Bounds = new Rectangle(_wideDownload.Left - S(5) - tabWidth, tabTop, tabWidth, tabHeight);
|
||||
_trendHeading.Text = "本机代理趋势";
|
||||
_trendHeading.Bounds = new Rectangle(pad, tabTop, _wideUpload.Left - pad - S(8), tabHeight);
|
||||
_trendHeading.TextAlign = ContentAlignment.MiddleLeft;
|
||||
_trafficChart.Font = _wideChartFont;
|
||||
var chartTop = _wideUpload.Bottom + S(3);
|
||||
_trafficChart.Bounds = new Rectangle(S(10), chartTop, trendWidth - S(20), _speedTrendCard.Height - chartTop - S(7));
|
||||
_trafficChart.Bounds = new Rectangle(S(9), chartTop, trendWidth - S(18), _speedTrendCard.Height - chartTop - S(6));
|
||||
|
||||
var totalsHeight = _dailyCard.Height;
|
||||
var titleWidth = Math.Min(S(155), _dailyCard.Width / 4);
|
||||
_dailyIcon.Bounds = new Rectangle(S(12), (totalsHeight - S(28)) / 2, S(28), S(28));
|
||||
_dailyHeading.Bounds = new Rectangle(S(47), 0, Math.Max(1, titleWidth - S(48)), totalsHeight);
|
||||
var titleWidth = S(140);
|
||||
var iconSize = S(18);
|
||||
_dailyIcon.Bounds = new Rectangle(pad, (totalsHeight - iconSize) / 2, iconSize, iconSize);
|
||||
_dailyHeading.Bounds = new Rectangle(_dailyIcon.Right + S(8), 0, titleWidth - _dailyIcon.Right - S(8), totalsHeight);
|
||||
_dailyHeading.TextAlign = ContentAlignment.MiddleLeft;
|
||||
var metricWidth = (_dailyCard.Width - titleWidth - S(9)) / 2;
|
||||
_usageMetric.Bounds = new Rectangle(titleWidth, S(3), metricWidth, totalsHeight - S(9));
|
||||
_sessionMetric.Bounds = new Rectangle(_usageMetric.Right, S(3), metricWidth, totalsHeight - S(9));
|
||||
var metricWidth = Math.Min(S(178), (_dailyCard.Width - titleWidth - pad) / 2);
|
||||
_usageMetric.Bounds = new Rectangle(titleWidth, S(1), metricWidth, totalsHeight - S(3));
|
||||
_sessionMetric.Bounds = new Rectangle(_usageMetric.Right, S(1), metricWidth, totalsHeight - S(3));
|
||||
|
||||
var footerHeight = _footer.Height;
|
||||
_wideFooterClock.Bounds = new Rectangle(S(11), (footerHeight - S(22)) / 2, S(22), S(22));
|
||||
_expiryLabel.Bounds = new Rectangle(S(40), 0, S(126), footerHeight);
|
||||
_wideFooterShield.Bounds = new Rectangle(S(171), (footerHeight - S(22)) / 2, S(22), S(22));
|
||||
_wideFooterState.Bounds = new Rectangle(S(200), 0, Math.Max(1, _footer.Width - S(452)), footerHeight);
|
||||
_footerHint.Bounds = new Rectangle(_footer.Width - S(243), 0, S(229), footerHeight);
|
||||
_footerHint.Visible = true;
|
||||
_planLabel.Visible = _footerPoem.Visible = false;
|
||||
_wideSidebarPlan.Text = _planLabel.Text;
|
||||
_expiryLabel.Bounds = new Rectangle(pad, 0, S(110), footerHeight);
|
||||
_planLabel.Bounds = new Rectangle(_expiryLabel.Right + S(8), 0, _footer.Width - S(390), footerHeight);
|
||||
_footerHint.Bounds = new Rectangle(_footer.Width - S(229) - pad, 0, S(229), footerHeight);
|
||||
_footerHint.Visible = _planLabel.Visible = true;
|
||||
_footerPoem.Visible = false;
|
||||
}
|
||||
|
||||
private void RefreshConnectionAppearance()
|
||||
@@ -265,8 +205,7 @@ internal sealed partial class MainForm
|
||||
_ => Color.FromArgb(13, 99, 195),
|
||||
} : accent;
|
||||
_statusDot.Featured = _statusCard.WideBanner;
|
||||
_wideFooterShield.ForeColor = accent;
|
||||
_statusDot.Glyph = _wideFooterShield.Glyph = tone switch
|
||||
_statusDot.Glyph = tone switch
|
||||
{
|
||||
BannerTone.Connected => DashboardIcon.Shield,
|
||||
BannerTone.Error or BannerTone.Attention => DashboardIcon.ShieldAlert,
|
||||
@@ -276,7 +215,6 @@ internal sealed partial class MainForm
|
||||
_wideSummaryState.Text = _selectionUiConnected
|
||||
? (_currentNodeUsesTailnet ? "● Tailscale 入口" : "● 公网入口")
|
||||
: "● " + title;
|
||||
_wideFooterState.Text = tone == BannerTone.Connected ? "网络连接 · 已连接" : "网络连接 · " + title;
|
||||
_footerCompanySite.Text = tone switch
|
||||
{
|
||||
BannerTone.Connected => "网络 · 已连接",
|
||||
@@ -288,76 +226,3 @@ internal sealed partial class MainForm
|
||||
_footerCompanySite.ForeColor = accent;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TrendSummaryPanel : CardPanel
|
||||
{
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
if (Width < 20 || Height < 48) return;
|
||||
var g = e.Graphics;
|
||||
var state = g.Save();
|
||||
var scale = DeviceDpi / 96f;
|
||||
var inset = Math.Max(1, (int)Math.Round(scale * 2));
|
||||
using var clip = UiGeometry.RoundedRectangle(new Rectangle(inset, inset, Width - 2 * inset - 1, Height - 2 * inset - 2),
|
||||
Math.Min((int)Math.Round(12 * scale), (Height - 2 * inset - 2) / 2));
|
||||
g.SetClip(clip, CombineMode.Intersect);
|
||||
var y = Height * .84f;
|
||||
using var wave = new GraphicsPath();
|
||||
wave.AddBezier(0, y, Width * .35f, Height * .43f, Width * .52f, Height * 1.25f, Width, Height * .66f);
|
||||
wave.AddLine(Width, Height, 0, Height);
|
||||
wave.CloseFigure();
|
||||
using var fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(36, 117, 194, 244), Color.FromArgb(80, 114, 192, 246), 90);
|
||||
using var line = new Pen(Color.FromArgb(96, 66, 152, 217), Math.Max(1f, .7f * scale));
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.FillPath(fill, wave);
|
||||
g.DrawBezier(line, 0, y, Width * .35f, Height * .43f, Width * .52f, Height * 1.25f, Width, Height * .66f);
|
||||
g.Restore(state);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DashboardFeature : Control
|
||||
{
|
||||
private readonly DashboardIcon _icon;
|
||||
private readonly string _title, _detail;
|
||||
private readonly bool _divider;
|
||||
|
||||
internal DashboardFeature(DashboardIcon icon, string title, string detail, bool divider = false)
|
||||
{
|
||||
_icon = icon;
|
||||
_title = title;
|
||||
_detail = detail;
|
||||
_divider = divider;
|
||||
SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
|
||||
BackColor = Color.Transparent;
|
||||
AccessibleName = title;
|
||||
AccessibleDescription = detail;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
var g = e.Graphics;
|
||||
var scale = DeviceDpi / 96f;
|
||||
int S(float value) => (int)Math.Round(value * scale);
|
||||
var side = Math.Min(S(36), Height - S(6));
|
||||
var icon = new Rectangle(S(5), (Height - side) / 2, side, side);
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
using var bubble = new SolidBrush(Color.FromArgb(92, 174, 217, 251));
|
||||
g.FillEllipse(bubble, icon);
|
||||
DashboardDrawing.Icon(g, _icon, Rectangle.Inflate(icon, -S(7), -S(7)), Brand.DeepBlue);
|
||||
using var title = Brand.Font(10.5f, FontStyle.Bold);
|
||||
using var detail = Brand.Font(8.5f);
|
||||
var x = icon.Right + S(10);
|
||||
var width = Width - x - S(4);
|
||||
var middle = Height / 2;
|
||||
if (_divider && Height >= S(38))
|
||||
{
|
||||
using var divider = new Pen(Color.FromArgb(108, 167, 198, 223), Math.Max(1f, .65f * scale));
|
||||
g.DrawLine(divider, S(6), 0, Width - S(7), 0);
|
||||
}
|
||||
var flags = TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;
|
||||
TextRenderer.DrawText(g, _title, title, new Rectangle(x, middle - S(16), width, S(18)), Brand.Navy, flags);
|
||||
TextRenderer.DrawText(g, _detail, detail, new Rectangle(x, middle + S(2), width, S(16)), Brand.Muted, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +1,132 @@
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal sealed partial class MainForm
|
||||
{
|
||||
private void ExerciseWideDashboardPreview(Dictionary<string, bool> checks, Action<string> capture)
|
||||
{
|
||||
var compactSize = ClientSize;
|
||||
ClientSize = new Size(ScaleLogical(1160), ScaleLogical(738));
|
||||
LayoutBrandHeader();
|
||||
LayoutDashboard();
|
||||
checks["wide_geometry_all_viewport_and_dpi_cases"] = DashboardWideLayout.SelfTest();
|
||||
checks["wide_header_account_and_actions"] = _dashboardHeaderName.Visible
|
||||
&& _dashboardHeaderName.Text == _welcomeLabel.Text
|
||||
&& _dashboardSettings.Visible && _dashboardAbout.Visible && _dashboardLogout.Visible && _dashboardClose.Visible
|
||||
&& !_welcomeLabel.Visible && !_logoutButton.Visible;
|
||||
checks["wide_reuses_configuration_and_range_controls"] = _connectionModeCombo.Parent == _nodeCard
|
||||
&& _routeCombo.Parent == _nodeCard && _historyRangeCombo.Parent == _modeCard
|
||||
&& _connectionModeCombo.Enabled && _routeCombo.Enabled && _historyRangeCombo.Enabled;
|
||||
|
||||
_connectionModeCombo.SelectedIndex = 1;
|
||||
checks["wide_manual_node_visible_and_fitted"] = _manualNodeCombo.Visible && _manualNodeCombo.Items.Count > 0 && DashboardControlsFit();
|
||||
_connectionModeCombo.SelectedIndex = 0;
|
||||
SetConnectionState(false, "未连接", "连接后显示代理速度趋势");
|
||||
checks["wide_disconnected_and_no_fake_speed"] = _statusCard.Tone == BannerTone.Idle && _connectButton.Text == "连接"
|
||||
&& _wideUpload.Text.EndsWith("—") && _wideDownload.Text.EndsWith("—");
|
||||
capture("wide-disconnected");
|
||||
|
||||
using (var pending = new CancellationTokenSource())
|
||||
{
|
||||
_connectionAttemptCancellation = pending;
|
||||
SetConnectionState(false, "正在连接", "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
SetBusy(true, "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
checks["wide_connecting_can_cancel"] = _statusCard.Tone == BannerTone.Connecting
|
||||
&& _connectButton.Text == "取消连接" && _connectButton.Enabled
|
||||
&& !_connectionModeCombo.Enabled && !_routeCombo.Enabled;
|
||||
capture("wide-connecting");
|
||||
checks["wide_cancel_handler_cancels_owned_attempt"] = TryCancelPendingConnection()
|
||||
&& pending.IsCancellationRequested && !_connectButton.Enabled && _statusDetail.Text.Contains("取消");
|
||||
_connectionAttemptCancellation = null;
|
||||
SetBusy(false);
|
||||
}
|
||||
|
||||
SetConnectionState(true, "已安全连接", "VPN002 · Tailscale 入口 · AI 智能代理");
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
for (var i = 0; i < 60; i++)
|
||||
_trafficChart.Add(120000 + Math.Sin(i / 3d) * 50000, 600000 + Math.Cos(i / 7d) * 220000, now.AddSeconds(5 * (i - 59)));
|
||||
DisplayTraffic(180000, 920000, "演示样本 · 近 5 分钟");
|
||||
_wideDownload.PerformClick();
|
||||
checks["wide_download_tab_changes_chart_series"] = _trafficChart.DisplayedSeries == TrafficChartSeries.Download
|
||||
&& _wideDownload.Text.Contains("KB/s") && _wideUpload.Text.Contains("KB/s");
|
||||
_wideUpload.PerformClick();
|
||||
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[2];
|
||||
checks["wide_upload_tab_and_range_use_existing_chart"] = _trafficChart.DisplayedSeries == TrafficChartSeries.Upload
|
||||
&& _trafficChart.PeriodMinutes == 15;
|
||||
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[1];
|
||||
checks["wide_connected_has_disconnect_and_live_values"] = _statusCard.Tone == BannerTone.Connected
|
||||
&& _connectButton.Text == "断开连接" && !_routeCombo.Enabled && DashboardControlsFit();
|
||||
capture("wide-connected");
|
||||
|
||||
checks["wide_degraded_retains_disconnect"] = TryShowConnectionHealthWarning(ConnectionHealthPolicy.Decision.WebsiteUnavailable)
|
||||
&& _statusCard.Tone == BannerTone.Attention && _connectButton.Text == "断开连接";
|
||||
checks["wide_website_warning_confirms_proxy_and_fits_width"] = _statusDetail.Text.Contains("代理出口可达") && WarningTextFitsWidth();
|
||||
capture("wide-website-warning");
|
||||
|
||||
checks["wide_tailnet_egress_warning_retains_ingress_and_disconnect"] =
|
||||
TryShowConnectionHealthWarning(ConnectionHealthPolicy.Decision.TailnetEgressUnverified)
|
||||
&& _statusCard.Tone == BannerTone.Attention && _connectButton.Text == "断开连接"
|
||||
&& _wideSummaryState.Text.Contains("Tailscale 入口");
|
||||
checks["wide_tailnet_egress_warning_reports_uncertainty_and_fits_width"] = _statusDetail.Text.Contains("代理出口尚未确认") && WarningTextFitsWidth();
|
||||
capture("wide-tailnet-egress-warning");
|
||||
|
||||
SetConnectionState(true, "已恢复安全连接", "VPN002 · Tailscale 入口");
|
||||
checks["wide_recovered_is_connected"] = _statusCard.Tone == BannerTone.Connected && _displayedHealthWarning is null;
|
||||
SetConnectionState(false, "连接失败", "请检查当前网络和节点状态,再试一次。");
|
||||
_trafficChart.Reset();
|
||||
checks["wide_error_detail_and_retry_remain_visible"] = _statusCard.Tone == BannerTone.Error
|
||||
&& _statusDetail.Text.Contains("检查当前网络") && _connectButton.Text == "连接" && _connectButton.Enabled;
|
||||
capture("wide-error");
|
||||
|
||||
ClientSize = new Size(ScaleLogical(840), ScaleLogical(480));
|
||||
LayoutDashboard();
|
||||
checks["wide_minimum_children_fit"] = WideDashboardPresentation && _wideMonitor.Visible && DashboardControlsFit();
|
||||
capture("wide-minimum");
|
||||
SetNodeTrafficPermission(true);
|
||||
LayoutDashboard();
|
||||
checks["wide_minimum_permission_panel_preserved"] = _nodeTrafficPanel.Visible
|
||||
&& _nodeTrafficPanel.Top > _speedTrendCard.Bottom && _nodeTrafficPanel.Bottom < _dailyCard.Top
|
||||
&& _trafficChart.Height >= ScaleLogical(40) && DashboardControlsFit();
|
||||
capture("wide-minimum-server-panel");
|
||||
SetNodeTrafficPermission(false);
|
||||
|
||||
var screen = Screen.FromControl(this).WorkingArea;
|
||||
var realWidth = Math.Min(ScaleLogical(1160), screen.Width - ScaleLogical(16));
|
||||
var realHeight = Math.Min(ScaleLogical(738), screen.Height - ScaleLogical(16));
|
||||
if (realWidth >= ScaleLogical(840) && realHeight >= ScaleLogical(480))
|
||||
{
|
||||
ClientSize = new Size(realWidth, realHeight);
|
||||
LayoutDashboard();
|
||||
checks["wide_fits_actual_screen_work_area"] = _wideMonitor.Visible && Width <= screen.Width
|
||||
&& Height <= screen.Height && DashboardControlsFit();
|
||||
SetConnectionState(false, "正在连接", "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
using var screenAttempt = new CancellationTokenSource();
|
||||
_connectionAttemptCancellation = screenAttempt;
|
||||
SetBusy(true, "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
capture("wide-current-screen");
|
||||
_connectionAttemptCancellation = null;
|
||||
SetBusy(false);
|
||||
SetConnectionState(false, "未连接", "点击连接,AI 自动选择工作节点");
|
||||
}
|
||||
ClientSize = compactSize;
|
||||
LayoutBrandHeader();
|
||||
LayoutDashboard();
|
||||
checks["return_to_compact_restores_chart_and_controls"] = !_wideMonitor.Visible && _modeCard.Parent == _nodeCard
|
||||
&& _historyRangeCombo.Parent == _speedTrendCard && _trafficChart.DisplayedSeries == TrafficChartSeries.Both
|
||||
&& !_dashboardSettings.Visible && _dashboardMore.Visible && DashboardControlsFit();
|
||||
capture("compact-final");
|
||||
|
||||
bool WarningTextFitsWidth()
|
||||
{
|
||||
using var graphics = _statusCard.CreateGraphics();
|
||||
return FitsWidth(_statusTitle) && FitsWidth(_statusDetail);
|
||||
|
||||
bool FitsWidth(Label label) => TextRenderer.MeasureText(graphics, label.Text, label.Font).Width <= label.ClientSize.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal sealed partial class MainForm
|
||||
{
|
||||
private void ExerciseWideDashboardPreview(Dictionary<string, bool> checks, Action<string> capture)
|
||||
{
|
||||
var compactSize = ClientSize;
|
||||
ClientSize = new Size(ScaleLogical(1160), ScaleLogical(738));
|
||||
LayoutBrandHeader();
|
||||
LayoutDashboard();
|
||||
checks["wide_geometry_all_viewport_and_dpi_cases"] = DashboardWideLayout.SelfTest();
|
||||
checks["wide_header_account_and_actions"] = _dashboardHeaderName.Visible
|
||||
&& _dashboardHeaderName.Text == _welcomeLabel.Text
|
||||
&& _dashboardSettings.Visible && _dashboardAbout.Visible && _dashboardLogout.Visible
|
||||
&& WindowChromeForTest is { LoginMode: false, MinimizeButton.Action: CaptionAction.Minimize }
|
||||
&& !_welcomeLabel.Visible && !_logoutButton.Visible;
|
||||
checks["wide_reuses_configuration_and_range_controls"] = _connectionModeCombo.Parent == _nodeCard
|
||||
&& _routeCombo.Parent == _nodeCard && _historyRangeCombo.Parent == _speedTrendCard
|
||||
&& _connectionModeCombo.Enabled && _routeCombo.Enabled && _historyRangeCombo.Enabled;
|
||||
|
||||
_connectionModeCombo.SelectedIndex = 1;
|
||||
checks["wide_manual_node_visible_and_fitted"] = _manualNodeCombo.Visible && _manualNodeCombo.Items.Count > 0 && DashboardControlsFit();
|
||||
_connectionModeCombo.SelectedIndex = 0;
|
||||
SetConnectionState(false, "未连接", "连接后显示代理速度趋势");
|
||||
checks["wide_disconnected_and_no_fake_speed"] = _statusCard.Tone == BannerTone.Idle && _connectButton.Text == "连接"
|
||||
&& _wideUpload.Text.EndsWith("—") && _wideDownload.Text.EndsWith("—");
|
||||
capture("wide-disconnected");
|
||||
|
||||
using (var pending = new CancellationTokenSource())
|
||||
{
|
||||
_connectionAttemptCancellation = pending;
|
||||
SetConnectionState(false, "正在连接", "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
SetBusy(true, "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
checks["wide_connecting_can_cancel"] = _statusCard.Tone == BannerTone.Connecting
|
||||
&& _connectButton.Text == "取消连接" && _connectButton.Enabled
|
||||
&& !_connectionModeCombo.Enabled && !_routeCombo.Enabled;
|
||||
capture("wide-connecting");
|
||||
checks["wide_cancel_handler_cancels_owned_attempt"] = TryCancelPendingConnection()
|
||||
&& pending.IsCancellationRequested && !_connectButton.Enabled && _statusDetail.Text.Contains("取消");
|
||||
_connectionAttemptCancellation = null;
|
||||
SetBusy(false);
|
||||
}
|
||||
|
||||
SetConnectionState(true, "已安全连接", "VPN002 · Tailscale 入口 · AI 智能代理");
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
for (var i = 0; i < 60; i++)
|
||||
_trafficChart.Add(120000 + Math.Sin(i / 3d) * 50000, 600000 + Math.Cos(i / 7d) * 220000, now.AddSeconds(5 * (i - 59)));
|
||||
DisplayTraffic(180000, 920000, "演示样本 · 近 5 分钟");
|
||||
checks["wide_shows_both_series_and_aligns_chart_heading"] =
|
||||
_trafficChart.DisplayedSeries == TrafficChartSeries.Both && _trendHeading.Top == _wideUpload.Top
|
||||
&& _wideUpload.Top == _historyRangeCombo.Top && _trendHeading.Right <= _wideUpload.Left;
|
||||
_wideDownload.PerformClick();
|
||||
checks["wide_download_tab_changes_chart_series"] = _trafficChart.DisplayedSeries == TrafficChartSeries.Download
|
||||
&& _wideDownload.Text.Contains("KB/s") && _wideUpload.Text.Contains("KB/s");
|
||||
_wideUpload.PerformClick();
|
||||
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[2];
|
||||
checks["wide_upload_tab_and_range_use_existing_chart"] = _trafficChart.DisplayedSeries == TrafficChartSeries.Upload
|
||||
&& _trafficChart.PeriodMinutes == 15;
|
||||
_wideUpload.PerformClick();
|
||||
checks["wide_selected_series_toggles_back_to_both"] = _trafficChart.DisplayedSeries == TrafficChartSeries.Both;
|
||||
_historyRangeCombo.SelectedItem = SpeedHistoryPeriod.All[1];
|
||||
checks["wide_connected_has_disconnect_and_live_values"] = _statusCard.Tone == BannerTone.Connected
|
||||
&& _connectButton.Text == "断开连接" && !_routeCombo.Enabled && DashboardControlsFit();
|
||||
capture("wide-connected");
|
||||
|
||||
checks["wide_degraded_retains_disconnect"] = TryShowConnectionHealthWarning(ConnectionHealthPolicy.Decision.WebsiteUnavailable)
|
||||
&& _statusCard.Tone == BannerTone.Attention && _connectButton.Text == "断开连接";
|
||||
checks["wide_website_warning_confirms_proxy_and_fits_width"] = _statusDetail.Text.Contains("代理出口可达") && WarningTextFitsWidth();
|
||||
capture("wide-website-warning");
|
||||
|
||||
checks["wide_tailnet_egress_warning_retains_ingress_and_disconnect"] =
|
||||
TryShowConnectionHealthWarning(ConnectionHealthPolicy.Decision.TailnetEgressUnverified)
|
||||
&& _statusCard.Tone == BannerTone.Attention && _connectButton.Text == "断开连接"
|
||||
&& _wideSummaryState.Text.Contains("Tailscale 入口");
|
||||
checks["wide_tailnet_egress_warning_reports_uncertainty_and_fits_width"] = _statusDetail.Text.Contains("代理出口尚未确认") && WarningTextFitsWidth();
|
||||
capture("wide-tailnet-egress-warning");
|
||||
|
||||
SetConnectionState(true, "已恢复安全连接", "VPN002 · Tailscale 入口");
|
||||
checks["wide_recovered_is_connected"] = _statusCard.Tone == BannerTone.Connected && _displayedHealthWarning is null;
|
||||
SetConnectionState(false, "连接失败", "请检查当前网络和节点状态,再试一次。");
|
||||
_trafficChart.Reset();
|
||||
checks["wide_error_detail_and_retry_remain_visible"] = _statusCard.Tone == BannerTone.Error
|
||||
&& _statusDetail.Text.Contains("检查当前网络") && _connectButton.Text == "连接" && _connectButton.Enabled;
|
||||
capture("wide-error");
|
||||
|
||||
ClientSize = new Size(ScaleLogical(840), ScaleLogical(480));
|
||||
LayoutDashboard();
|
||||
checks["wide_minimum_children_fit"] = WideDashboardPresentation && _wideMonitor.Visible && DashboardControlsFit();
|
||||
capture("wide-minimum");
|
||||
SetNodeTrafficPermission(true);
|
||||
LayoutDashboard();
|
||||
checks["wide_minimum_permission_panel_preserved"] = _nodeTrafficPanel.Visible
|
||||
&& _nodeTrafficPanel.Top > _speedTrendCard.Bottom && _nodeTrafficPanel.Bottom < _dailyCard.Top
|
||||
&& _trafficChart.Height >= ScaleLogical(40) && DashboardControlsFit();
|
||||
capture("wide-minimum-server-panel");
|
||||
SetNodeTrafficPermission(false);
|
||||
|
||||
var screen = Screen.FromControl(this).WorkingArea;
|
||||
var realWidth = Math.Min(ScaleLogical(1160), screen.Width - ScaleLogical(16));
|
||||
var realHeight = Math.Min(ScaleLogical(738), screen.Height - ScaleLogical(16));
|
||||
if (realWidth >= ScaleLogical(840) && realHeight >= ScaleLogical(480))
|
||||
{
|
||||
ClientSize = new Size(realWidth, realHeight);
|
||||
LayoutDashboard();
|
||||
checks["wide_fits_actual_screen_work_area"] = _wideMonitor.Visible && Width <= screen.Width
|
||||
&& Height <= screen.Height && DashboardControlsFit();
|
||||
SetConnectionState(false, "正在连接", "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
using var screenAttempt = new CancellationTokenSource();
|
||||
_connectionAttemptCancellation = screenAttempt;
|
||||
SetBusy(true, "VPN002 · 正在验证 Tailscale 节点入口");
|
||||
capture("wide-current-screen");
|
||||
_connectionAttemptCancellation = null;
|
||||
SetBusy(false);
|
||||
SetConnectionState(false, "未连接", "点击连接,AI 自动选择工作节点");
|
||||
}
|
||||
ClientSize = compactSize;
|
||||
LayoutBrandHeader();
|
||||
LayoutDashboard();
|
||||
checks["return_to_compact_restores_chart_and_controls"] = !_wideMonitor.Visible && _modeCard.Parent == _nodeCard
|
||||
&& _historyRangeCombo.Parent == _speedTrendCard && _trafficChart.DisplayedSeries == TrafficChartSeries.Both
|
||||
&& !_dashboardSettings.Visible && _dashboardMore.Visible && DashboardControlsFit();
|
||||
capture("compact-final");
|
||||
|
||||
bool WarningTextFitsWidth()
|
||||
{
|
||||
using var graphics = _statusCard.CreateGraphics();
|
||||
return FitsWidth(_statusTitle) && FitsWidth(_statusDetail);
|
||||
|
||||
bool FitsWidth(Label label) => TextRenderer.MeasureText(graphics, label.Text, label.Font).Width <= label.ClientSize.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -1,5 +1,9 @@
|
||||
# 优创⁺纵横家 Windows 客户端
|
||||
|
||||
## Windows 0.3.18
|
||||
|
||||
宽屏和紧凑窗口采用同一阅读顺序。左侧设置调度与代理模式,右侧显示生效的节点和模式。本机上传与下载趋势默认同屏,下方显示有权限查看的服务器走势。累计用量使用一条数字栏。登录后的窗口按钮收起到系统托盘,托盘图标提供恢复和退出。
|
||||
|
||||
## Windows 0.3.17
|
||||
|
||||
智能代理和全局代理优先验证已授权的 Tailscale 入口。内网代理端口或出口持续异常时,客户端通过同一节点的公网入口重新连接,并在收到经代理转发的 HTTPS 响应后显示连接成功。切换网络后重新验证代理出口,Tailscale 控制和中继流量使用直连路由。
|
||||
@@ -9,7 +13,7 @@
|
||||
1. 验收客户端连接、断开及覆盖升级,发布同一构建的源码标签和安装包,从旧客户端核对更新提示及安装包摘要。
|
||||
2. 将同一版本登记到公司内部资源中心,并验证员工可下载。
|
||||
3. 在公司网站「公司动态」发布版本新闻并配一张产品图,匿名检查栏目、正文和配图。
|
||||
4. 经小小优运维发送本次更新通知,核对发送回执。发布重试时按产品、平台及版本查找现有记录。
|
||||
4. 在尚书台「通知」频道发布公司更新通知,核对发送回执。发布重试时按产品、平台及版本查找现有记录。
|
||||
|
||||
## Windows 0.3.8
|
||||
|
||||
|
||||
+253
-252
@@ -1,252 +1,253 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal static class StartupSelfTest
|
||||
{
|
||||
// Runs real WinForms first-show/resize/restore behavior, but never reads a
|
||||
// login token, calls the platform API, starts a core or touches networking.
|
||||
internal static int Run()
|
||||
{
|
||||
var report = new Dictionary<string, object>();
|
||||
try
|
||||
{
|
||||
using (var control = new Control())
|
||||
{
|
||||
_ = control.Handle;
|
||||
report["synchronization_context"] = SynchronizationContext.Current?.GetType().Name ?? "none";
|
||||
async Task OldBlockingPattern() { await Task.Delay(100); }
|
||||
var old = OldBlockingPattern();
|
||||
report["old_sync_wait_would_block"] = !old.Wait(350);
|
||||
// Resume only this synthetic callback after the bounded probe.
|
||||
Application.DoEvents();
|
||||
}
|
||||
var recoveryFinished = false;
|
||||
var heartbeat = 0;
|
||||
var visibleDuringRecovery = false;
|
||||
var watch = Stopwatch.StartNew();
|
||||
using var form = new MainForm(uiOnly: true, startupRecovery: async token =>
|
||||
{
|
||||
await Task.Delay(1400, token);
|
||||
recoveryFinished = true;
|
||||
});
|
||||
form.TopMost = true; // Owned UI fixture only; never a production window policy.
|
||||
using var timer = new System.Windows.Forms.Timer { Interval = 80 };
|
||||
var passed = false;
|
||||
timer.Tick += async (_, _) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
heartbeat++;
|
||||
if (!recoveryFinished && form.LoginFieldsVisibleForTest) visibleDuringRecovery = true;
|
||||
if (recoveryFinished && heartbeat >= 22)
|
||||
{
|
||||
timer.Stop(); // Input probes resume through the normal UI message loop.
|
||||
report["first_login_visible_while_recovering"] = visibleDuringRecovery;
|
||||
report["login_ready_after_recovery"] = form.LoginReadyForTest;
|
||||
report["registration_text_and_link_same_row"] = form.LoginRegistrationAlignedForTest;
|
||||
var registrationDpiPass = true;
|
||||
foreach (var dpi in new[] { 96, 120, 144, 168, 192, 240, 288 })
|
||||
{
|
||||
int S(int n) => (int)Math.Round(n * dpi / 96f);
|
||||
// Geometry fixture only; not a claim of physical
|
||||
// per-monitor rendering at these simulated DPIs.
|
||||
var row = MainForm.LoginRegistrationBounds(S(440), dpi, new Size(S(92), S(18)), new Size(S(86), S(18)));
|
||||
registrationDpiPass &= row.Prompt.Top == row.Link.Top && row.Prompt.Height == row.Link.Height
|
||||
&& row.Prompt.Right < row.Link.Left && row.Prompt.Left >= S(28) && row.Link.Right <= S(412)
|
||||
&& Math.Abs((row.Prompt.Left + row.Link.Right) / 2f - S(440) / 2f) <= 1
|
||||
&& row.Prompt.Bottom <= S(306);
|
||||
}
|
||||
report["registration_geometry_100_to_300_percent"] = registrationDpiPass;
|
||||
CheckLoginSurface(report);
|
||||
report["dpi"] = form.DeviceDpi;
|
||||
report["ui_heartbeat_ticks"] = heartbeat;
|
||||
var chrome = form.WindowChromeForTest
|
||||
?? throw new InvalidOperationException("Owned MainForm did not initialize window chrome");
|
||||
report["login_caption_is_exit_not_minimize"] = chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Close
|
||||
&& chrome.MinimizeButton.AccessibleName == "退出软件";
|
||||
// A separate UI-only window exercises the actual login
|
||||
// X -> RequestExit -> cleanup path, even during recovery.
|
||||
// It never loads credentials, starts a core or changes networking.
|
||||
using (var loginExitProbe = new MainForm(uiOnly: true,
|
||||
startupRecovery: token => Task.Delay(Timeout.Infinite, token)))
|
||||
{
|
||||
var closed = false;
|
||||
loginExitProbe.FormClosed += (_, _) => closed = true;
|
||||
loginExitProbe.Show();
|
||||
await Task.Delay(30);
|
||||
var exitChrome = loginExitProbe.WindowChromeForTest;
|
||||
var exitWasVisible = exitChrome is { LoginMode: true }
|
||||
&& exitChrome.MinimizeButton.Action == CaptionAction.Close;
|
||||
exitChrome?.MinimizeButton.PerformClick();
|
||||
report["login_x_closes_software_during_recovery"] = exitWasVisible
|
||||
&& closed && loginExitProbe.IsDisposed;
|
||||
}
|
||||
form.Activate();
|
||||
// Caption-state fixture only, not an authenticated login.
|
||||
// Keep the login card visible for the rendering checks.
|
||||
chrome.SetLoginMode(false);
|
||||
report["dashboard_caption_is_minimize_not_exit"] = !chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Minimize
|
||||
&& chrome.MinimizeButton.AccessibleName == "最小化";
|
||||
form.Close();
|
||||
// After authentication, only explicit menu/installer
|
||||
// exit may terminate the form; ordinary Close is blocked.
|
||||
report["ordinary_close_blocked_without_hiding"] = form.Visible && !form.IsDisposed;
|
||||
form.Hide(); // Synthetic tray-hidden state, not a close request.
|
||||
form.ShowFromTray();
|
||||
report["hidden_window_restored"] = form.LoginReadyForTest;
|
||||
form.WindowState = FormWindowState.Minimized;
|
||||
report["minimized_on_taskbar_without_exit"] = form.MinimizedOnTaskbarForTest;
|
||||
report["production_minimized_tray_available"] = MainForm.ShouldShowTrayIcon(FormWindowState.Minimized, false);
|
||||
report["production_restored_tray_available"] = MainForm.ShouldShowTrayIcon(FormWindowState.Normal, false);
|
||||
report["offline_preview_never_publishes_tray"] = Enum.GetValues<FormWindowState>()
|
||||
.All(state => !MainForm.ShouldShowTrayIcon(state, true));
|
||||
form.ShowFromTray();
|
||||
report["minimized_window_restored"] = form.WindowState == FormWindowState.Normal && form.LoginReadyForTest;
|
||||
var minimizeButton = form.Controls.OfType<BrandHeaderPanel>().Single().Controls.OfType<CaptionButton>().Single();
|
||||
var programmaticMinimize = await WindowChromeSelfTest.ProbeMinimizeInputAsync(form, minimizeButton, mouse: false);
|
||||
report["mainform_performclick_detail"] = programmaticMinimize;
|
||||
report["mainform_performclick_minimizes_on_taskbar"] = programmaticMinimize.Passed && form.MinimizedOnTaskbarForTest;
|
||||
form.ShowFromTray();
|
||||
var mouseMinimize = await WindowChromeSelfTest.ProbeMinimizeInputAsync(form, minimizeButton, mouse: true);
|
||||
report["mainform_mouse_minimize_detail"] = mouseMinimize;
|
||||
report["mainform_mouse_down_up_click_minimizes_on_taskbar"] = mouseMinimize.Passed && form.MinimizedOnTaskbarForTest;
|
||||
form.ShowFromTray();
|
||||
report["mainform_mouse_minimize_restores"] = form.WindowState == FormWindowState.Normal && form.LoginReadyForTest;
|
||||
chrome.SetLoginMode(true);
|
||||
report["return_to_login_restores_exit_caption"] = chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Close;
|
||||
var originalSize = form.Size;
|
||||
form.Size = form.MinimumSize;
|
||||
report["minimum_size_login_visible"] = form.LoginFieldsVisibleForTest;
|
||||
report["minimum_size_registration_aligned"] = form.LoginRegistrationAlignedForTest;
|
||||
form.Size = originalSize;
|
||||
using var screenshot = new Bitmap(form.Width, form.Height);
|
||||
form.DrawToBitmap(screenshot, new Rectangle(Point.Empty, screenshot.Size));
|
||||
screenshot.Save(Path.Combine(AppContext.BaseDirectory, "startup-login-test.png"));
|
||||
passed = visibleDuringRecovery && form.LoginReadyForTest
|
||||
&& report.Where(item => item.Value is bool).All(item => (bool)item.Value);
|
||||
timer.Stop();
|
||||
form.RequestExit();
|
||||
}
|
||||
else if (watch.Elapsed > TimeSpan.FromSeconds(12))
|
||||
{
|
||||
report["timeout"] = true;
|
||||
timer.Stop(); form.RequestExit();
|
||||
}
|
||||
}
|
||||
catch (Exception error) { report["error"] = error.ToString(); timer.Stop(); form.RequestExit(); }
|
||||
};
|
||||
form.Shown += (_, _) => timer.Start();
|
||||
Application.Run(form);
|
||||
report["passed"] = passed;
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "startup-self-test.json"),
|
||||
JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true }));
|
||||
return passed ? 0 : 20;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "startup-self-test.json"), error.ToString());
|
||||
return 21;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckLoginSurface(Dictionary<string, object> report)
|
||||
{
|
||||
// Owned, off-screen paint fixture only. Never capture the desktop or
|
||||
// use account values; these pixels are not production UI evidence.
|
||||
using var parent = new ScenicPanel { LoginArtwork = true };
|
||||
_ = parent.Handle;
|
||||
var fixtureDpi = parent.DeviceDpi;
|
||||
int S(int value) => (int)Math.Round(value * fixtureDpi / 96f);
|
||||
Point P(int x, int y) => new(S(x), S(y));
|
||||
parent.Size = new Size(S(900), S(640));
|
||||
using var card = new RoundedCardPanel { Bounds = new Rectangle(S(230), S(100), S(440), S(374)) };
|
||||
parent.Controls.Add(card);
|
||||
_ = card.Handle;
|
||||
using var first = new Bitmap(card.Width, card.Height);
|
||||
using var repeated = new Bitmap(card.Width, card.Height);
|
||||
using (var g = Graphics.FromImage(first)) g.Clear(Color.Magenta);
|
||||
using (var g = Graphics.FromImage(repeated)) g.Clear(Color.Lime);
|
||||
card.DrawToBitmap(first, card.ClientRectangle);
|
||||
for (var i = 0; i < 3; i++) card.DrawToBitmap(repeated, card.ClientRectangle);
|
||||
var stable = true;
|
||||
for (var x = S(36); x < card.Width - S(36); x += S(17))
|
||||
for (var y = S(36); y < card.Height - S(36); y += S(17))
|
||||
stable &= first.GetPixel(x, y).ToArgb() == repeated.GetPixel(x, y).ToArgb();
|
||||
report["login_surface_repaint_does_not_accumulate_alpha"] = stable;
|
||||
report["login_surface_is_not_opaque_white"] = first.GetPixel(S(40), S(300)).ToArgb() != Color.White.ToArgb();
|
||||
report["login_card_background_at_least_two_thirds_transparent"] = RoundedCardPanel.SurfaceAlpha <= 85;
|
||||
// The login card uses the blue glass surface (238,247,255), not pure
|
||||
// white. Keep the same strict pixel tolerance while predicting each
|
||||
// channel of that tint over the artwork in parent coordinates.
|
||||
Color Tint(Color background)
|
||||
{
|
||||
int Channel(int value, int tint) => (tint * RoundedCardPanel.SurfaceAlpha
|
||||
+ value * (255 - RoundedCardPanel.SurfaceAlpha)) / 255;
|
||||
return Color.FromArgb(Channel(background.R, 238), Channel(background.G, 247), Channel(background.B, 255));
|
||||
}
|
||||
var tintedPlainSurface = Tint(Brand.Surface);
|
||||
var sceneryVisible = false;
|
||||
var contrast = double.MaxValue;
|
||||
for (var x = S(36); x < card.Width - S(36); x += S(17))
|
||||
for (var y = S(36); y < card.Height - S(36); y += S(17))
|
||||
{
|
||||
var background = first.GetPixel(x, y);
|
||||
contrast = Math.Min(contrast, Contrast(Brand.Navy, background));
|
||||
if (y < S(170))
|
||||
sceneryVisible |= Math.Abs(background.R - tintedPlainSurface.R)
|
||||
+ Math.Abs(background.G - tintedPlainSurface.G) + Math.Abs(background.B - tintedPlainSurface.B) > 12;
|
||||
}
|
||||
report["login_landscape_visible_behind_upper_card"] = sceneryVisible;
|
||||
report["login_secondary_text_contrast_at_least_4_5"] = contrast >= 4.5;
|
||||
report["login_secondary_text_minimum_contrast"] = Math.Round(contrast, 3);
|
||||
card.Location = P(130, 220);
|
||||
using var moved = new Bitmap(card.Width, card.Height);
|
||||
card.DrawToBitmap(moved, card.ClientRectangle);
|
||||
using var backdrop = new Bitmap(parent.Width, parent.Height);
|
||||
using (var g = Graphics.FromImage(backdrop))
|
||||
ScenicTheme.Backdrop(g, parent.ClientSize, fixtureDpi, login: true);
|
||||
report["login_lower_scene_embedded"] = ScenicTheme.LoginSceneAvailable;
|
||||
var (sceneArea, sceneSource) = ScenicTheme.LoginSceneLayout(parent.ClientSize);
|
||||
report["login_lower_scene_avoids_original_black_borders"] = sceneSource.Left >= 352 && sceneSource.Right <= 2270;
|
||||
report["login_lower_scene_preserves_aspect_and_stays_below_header"] = sceneArea.Bottom == parent.Height
|
||||
&& sceneArea.Top >= parent.Height / 3 && Math.Abs(sceneArea.Width / (double)sceneArea.Height
|
||||
- sceneSource.Width / (double)sceneSource.Height) < .01;
|
||||
var lowerDetail = backdrop.GetPixel(parent.Width * 4 / 5, parent.Height * 4 / 5);
|
||||
report["login_lower_scene_visible_in_previously_empty_area"] = Math.Abs(lowerDetail.R - Brand.Surface.R)
|
||||
+ Math.Abs(lowerDetail.G - Brand.Surface.G) + Math.Abs(lowerDetail.B - Brand.Surface.B) > 30;
|
||||
var originCorrect = true;
|
||||
var maximumChannelError = 0;
|
||||
var originPixels = new List<object>();
|
||||
foreach (var point in new[] { P(40, 180), P(220, 300), P(400, 330) })
|
||||
{
|
||||
var background = backdrop.GetPixel(card.Left + point.X, card.Top + point.Y);
|
||||
var actual = moved.GetPixel(point.X, point.Y);
|
||||
var expected = Tint(background);
|
||||
var difference = Math.Max(Math.Abs(actual.R - expected.R),
|
||||
Math.Max(Math.Abs(actual.G - expected.G), Math.Abs(actual.B - expected.B)));
|
||||
maximumChannelError = Math.Max(maximumChannelError, difference);
|
||||
originCorrect &= difference <= 2;
|
||||
originPixels.Add(new { point.X, point.Y, background = background.ToArgb(), actual = actual.ToArgb(), expected = expected.ToArgb(), difference });
|
||||
}
|
||||
report["login_surface_move_pixel_probes"] = originPixels;
|
||||
report["login_surface_move_maximum_channel_error"] = maximumChannelError;
|
||||
report["login_surface_move_keeps_parent_artwork_coordinates"] = originCorrect;
|
||||
}
|
||||
|
||||
private static double Contrast(Color foreground, Color background)
|
||||
{
|
||||
static double Luminance(Color color)
|
||||
{
|
||||
static double Linear(byte value) => value / 255d <= .04045
|
||||
? value / 255d / 12.92 : Math.Pow((value / 255d + .055) / 1.055, 2.4);
|
||||
return .2126 * Linear(color.R) + .7152 * Linear(color.G) + .0722 * Linear(color.B);
|
||||
}
|
||||
var a = Luminance(foreground); var b = Luminance(background);
|
||||
return (Math.Max(a, b) + .05) / (Math.Min(a, b) + .05);
|
||||
}
|
||||
}
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal static class StartupSelfTest
|
||||
{
|
||||
// Runs real WinForms first-show/resize/restore behavior, but never reads a
|
||||
// login token, calls the platform API, starts a core or touches networking.
|
||||
internal static int Run()
|
||||
{
|
||||
var report = new Dictionary<string, object>();
|
||||
try
|
||||
{
|
||||
using (var control = new Control())
|
||||
{
|
||||
_ = control.Handle;
|
||||
report["synchronization_context"] = SynchronizationContext.Current?.GetType().Name ?? "none";
|
||||
async Task OldBlockingPattern() { await Task.Delay(100); }
|
||||
var old = OldBlockingPattern();
|
||||
report["old_sync_wait_would_block"] = !old.Wait(350);
|
||||
// Resume only this synthetic callback after the bounded probe.
|
||||
Application.DoEvents();
|
||||
}
|
||||
var recoveryFinished = false;
|
||||
var heartbeat = 0;
|
||||
var visibleDuringRecovery = false;
|
||||
var watch = Stopwatch.StartNew();
|
||||
using var form = new MainForm(uiOnly: true, startupRecovery: async token =>
|
||||
{
|
||||
await Task.Delay(1400, token);
|
||||
recoveryFinished = true;
|
||||
});
|
||||
form.TopMost = true; // Owned UI fixture only; never a production window policy.
|
||||
using var timer = new System.Windows.Forms.Timer { Interval = 80 };
|
||||
var passed = false;
|
||||
timer.Tick += async (_, _) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
heartbeat++;
|
||||
if (!recoveryFinished && form.LoginFieldsVisibleForTest) visibleDuringRecovery = true;
|
||||
if (recoveryFinished && heartbeat >= 22)
|
||||
{
|
||||
timer.Stop(); // Input probes resume through the normal UI message loop.
|
||||
report["first_login_visible_while_recovering"] = visibleDuringRecovery;
|
||||
report["login_ready_after_recovery"] = form.LoginReadyForTest;
|
||||
report["registration_text_and_link_same_row"] = form.LoginRegistrationAlignedForTest;
|
||||
var registrationDpiPass = true;
|
||||
foreach (var dpi in new[] { 96, 120, 144, 168, 192, 240, 288 })
|
||||
{
|
||||
int S(int n) => (int)Math.Round(n * dpi / 96f);
|
||||
// Geometry fixture only; not a claim of physical
|
||||
// per-monitor rendering at these simulated DPIs.
|
||||
var row = MainForm.LoginRegistrationBounds(S(440), dpi, new Size(S(92), S(18)), new Size(S(86), S(18)));
|
||||
registrationDpiPass &= row.Prompt.Top == row.Link.Top && row.Prompt.Height == row.Link.Height
|
||||
&& row.Prompt.Right < row.Link.Left && row.Prompt.Left >= S(28) && row.Link.Right <= S(412)
|
||||
&& Math.Abs((row.Prompt.Left + row.Link.Right) / 2f - S(440) / 2f) <= 1
|
||||
&& row.Prompt.Bottom <= S(306);
|
||||
}
|
||||
report["registration_geometry_100_to_300_percent"] = registrationDpiPass;
|
||||
CheckLoginSurface(report);
|
||||
report["dpi"] = form.DeviceDpi;
|
||||
report["ui_heartbeat_ticks"] = heartbeat;
|
||||
var chrome = form.WindowChromeForTest
|
||||
?? throw new InvalidOperationException("Owned MainForm did not initialize window chrome");
|
||||
report["login_caption_is_exit_not_minimize"] = chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Close
|
||||
&& chrome.MinimizeButton.AccessibleName == "退出软件";
|
||||
// A separate UI-only window exercises the actual login
|
||||
// X -> RequestExit -> cleanup path, even during recovery.
|
||||
// It never loads credentials, starts a core or changes networking.
|
||||
using (var loginExitProbe = new MainForm(uiOnly: true,
|
||||
startupRecovery: token => Task.Delay(Timeout.Infinite, token)))
|
||||
{
|
||||
var closed = false;
|
||||
loginExitProbe.FormClosed += (_, _) => closed = true;
|
||||
loginExitProbe.Show();
|
||||
await Task.Delay(30);
|
||||
var exitChrome = loginExitProbe.WindowChromeForTest;
|
||||
var exitWasVisible = exitChrome is { LoginMode: true }
|
||||
&& exitChrome.MinimizeButton.Action == CaptionAction.Close;
|
||||
exitChrome?.MinimizeButton.PerformClick();
|
||||
report["login_x_closes_software_during_recovery"] = exitWasVisible
|
||||
&& closed && loginExitProbe.IsDisposed;
|
||||
}
|
||||
form.Activate();
|
||||
// Caption-state fixture only, not an authenticated login.
|
||||
// Keep the login card visible for the rendering checks.
|
||||
chrome.SetLoginMode(false);
|
||||
report["dashboard_caption_is_minimize_not_exit"] = !chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Minimize
|
||||
&& chrome.MinimizeButton.AccessibleName == "最小化";
|
||||
form.Close();
|
||||
// After authentication, only explicit menu/installer
|
||||
// exit may terminate the form; ordinary Close is blocked.
|
||||
report["ordinary_close_blocked_without_hiding"] = form.Visible && !form.IsDisposed;
|
||||
form.Hide(); // Synthetic tray-hidden state, not a close request.
|
||||
form.ShowFromTray();
|
||||
report["hidden_window_restored"] = form.LoginReadyForTest;
|
||||
form.WindowState = FormWindowState.Minimized;
|
||||
report["minimized_on_taskbar_without_exit"] = form.MinimizedOnTaskbarForTest;
|
||||
report["production_minimized_tray_available"] = MainForm.ShouldShowTrayIcon(FormWindowState.Minimized, false);
|
||||
report["production_restored_tray_available"] = MainForm.ShouldShowTrayIcon(FormWindowState.Normal, false);
|
||||
report["offline_preview_never_publishes_tray"] = Enum.GetValues<FormWindowState>()
|
||||
.All(state => !MainForm.ShouldShowTrayIcon(state, true));
|
||||
form.ShowFromTray();
|
||||
report["minimized_window_restored"] = form.WindowState == FormWindowState.Normal && form.LoginReadyForTest;
|
||||
var minimizeButton = form.Controls.OfType<BrandHeaderPanel>().Single().Controls.OfType<CaptionButton>().Single();
|
||||
var programmaticMinimize = await WindowChromeSelfTest.ProbeMinimizeInputAsync(form, minimizeButton, mouse: false, tray: true);
|
||||
report["mainform_performclick_detail"] = programmaticMinimize;
|
||||
report["mainform_performclick_hides_to_tray"] = programmaticMinimize.Passed && !form.IsDisposed;
|
||||
form.ShowFromTray();
|
||||
var mouseMinimize = await WindowChromeSelfTest.ProbeMinimizeInputAsync(form, minimizeButton, mouse: true, tray: true);
|
||||
report["mainform_mouse_minimize_detail"] = mouseMinimize;
|
||||
report["mainform_mouse_down_up_click_hides_to_tray"] = mouseMinimize.Passed && !form.IsDisposed;
|
||||
form.ShowFromTray();
|
||||
report["mainform_mouse_minimize_restores"] = form.WindowState == FormWindowState.Normal
|
||||
&& form.ShowInTaskbar && form.LoginReadyForTest;
|
||||
chrome.SetLoginMode(true);
|
||||
report["return_to_login_restores_exit_caption"] = chrome.LoginMode
|
||||
&& chrome.MinimizeButton.Action == CaptionAction.Close;
|
||||
var originalSize = form.Size;
|
||||
form.Size = form.MinimumSize;
|
||||
report["minimum_size_login_visible"] = form.LoginFieldsVisibleForTest;
|
||||
report["minimum_size_registration_aligned"] = form.LoginRegistrationAlignedForTest;
|
||||
form.Size = originalSize;
|
||||
using var screenshot = new Bitmap(form.Width, form.Height);
|
||||
form.DrawToBitmap(screenshot, new Rectangle(Point.Empty, screenshot.Size));
|
||||
screenshot.Save(Path.Combine(AppContext.BaseDirectory, "startup-login-test.png"));
|
||||
passed = visibleDuringRecovery && form.LoginReadyForTest
|
||||
&& report.Where(item => item.Value is bool).All(item => (bool)item.Value);
|
||||
timer.Stop();
|
||||
form.RequestExit();
|
||||
}
|
||||
else if (watch.Elapsed > TimeSpan.FromSeconds(12))
|
||||
{
|
||||
report["timeout"] = true;
|
||||
timer.Stop(); form.RequestExit();
|
||||
}
|
||||
}
|
||||
catch (Exception error) { report["error"] = error.ToString(); timer.Stop(); form.RequestExit(); }
|
||||
};
|
||||
form.Shown += (_, _) => timer.Start();
|
||||
Application.Run(form);
|
||||
report["passed"] = passed;
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "startup-self-test.json"),
|
||||
JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true }));
|
||||
return passed ? 0 : 20;
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "startup-self-test.json"), error.ToString());
|
||||
return 21;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckLoginSurface(Dictionary<string, object> report)
|
||||
{
|
||||
// Owned, off-screen paint fixture only. Never capture the desktop or
|
||||
// use account values; these pixels are not production UI evidence.
|
||||
using var parent = new ScenicPanel { LoginArtwork = true };
|
||||
_ = parent.Handle;
|
||||
var fixtureDpi = parent.DeviceDpi;
|
||||
int S(int value) => (int)Math.Round(value * fixtureDpi / 96f);
|
||||
Point P(int x, int y) => new(S(x), S(y));
|
||||
parent.Size = new Size(S(900), S(640));
|
||||
using var card = new RoundedCardPanel { Bounds = new Rectangle(S(230), S(100), S(440), S(374)) };
|
||||
parent.Controls.Add(card);
|
||||
_ = card.Handle;
|
||||
using var first = new Bitmap(card.Width, card.Height);
|
||||
using var repeated = new Bitmap(card.Width, card.Height);
|
||||
using (var g = Graphics.FromImage(first)) g.Clear(Color.Magenta);
|
||||
using (var g = Graphics.FromImage(repeated)) g.Clear(Color.Lime);
|
||||
card.DrawToBitmap(first, card.ClientRectangle);
|
||||
for (var i = 0; i < 3; i++) card.DrawToBitmap(repeated, card.ClientRectangle);
|
||||
var stable = true;
|
||||
for (var x = S(36); x < card.Width - S(36); x += S(17))
|
||||
for (var y = S(36); y < card.Height - S(36); y += S(17))
|
||||
stable &= first.GetPixel(x, y).ToArgb() == repeated.GetPixel(x, y).ToArgb();
|
||||
report["login_surface_repaint_does_not_accumulate_alpha"] = stable;
|
||||
report["login_surface_is_not_opaque_white"] = first.GetPixel(S(40), S(300)).ToArgb() != Color.White.ToArgb();
|
||||
report["login_card_background_at_least_two_thirds_transparent"] = RoundedCardPanel.SurfaceAlpha <= 85;
|
||||
// The login card uses the blue glass surface (238,247,255), not pure
|
||||
// white. Keep the same strict pixel tolerance while predicting each
|
||||
// channel of that tint over the artwork in parent coordinates.
|
||||
Color Tint(Color background)
|
||||
{
|
||||
int Channel(int value, int tint) => (tint * RoundedCardPanel.SurfaceAlpha
|
||||
+ value * (255 - RoundedCardPanel.SurfaceAlpha)) / 255;
|
||||
return Color.FromArgb(Channel(background.R, 238), Channel(background.G, 247), Channel(background.B, 255));
|
||||
}
|
||||
var tintedPlainSurface = Tint(Brand.Surface);
|
||||
var sceneryVisible = false;
|
||||
var contrast = double.MaxValue;
|
||||
for (var x = S(36); x < card.Width - S(36); x += S(17))
|
||||
for (var y = S(36); y < card.Height - S(36); y += S(17))
|
||||
{
|
||||
var background = first.GetPixel(x, y);
|
||||
contrast = Math.Min(contrast, Contrast(Brand.Navy, background));
|
||||
if (y < S(170))
|
||||
sceneryVisible |= Math.Abs(background.R - tintedPlainSurface.R)
|
||||
+ Math.Abs(background.G - tintedPlainSurface.G) + Math.Abs(background.B - tintedPlainSurface.B) > 12;
|
||||
}
|
||||
report["login_landscape_visible_behind_upper_card"] = sceneryVisible;
|
||||
report["login_secondary_text_contrast_at_least_4_5"] = contrast >= 4.5;
|
||||
report["login_secondary_text_minimum_contrast"] = Math.Round(contrast, 3);
|
||||
card.Location = P(130, 220);
|
||||
using var moved = new Bitmap(card.Width, card.Height);
|
||||
card.DrawToBitmap(moved, card.ClientRectangle);
|
||||
using var backdrop = new Bitmap(parent.Width, parent.Height);
|
||||
using (var g = Graphics.FromImage(backdrop))
|
||||
ScenicTheme.Backdrop(g, parent.ClientSize, fixtureDpi, login: true);
|
||||
report["login_lower_scene_embedded"] = ScenicTheme.LoginSceneAvailable;
|
||||
var (sceneArea, sceneSource) = ScenicTheme.LoginSceneLayout(parent.ClientSize);
|
||||
report["login_lower_scene_avoids_original_black_borders"] = sceneSource.Left >= 352 && sceneSource.Right <= 2270;
|
||||
report["login_lower_scene_preserves_aspect_and_stays_below_header"] = sceneArea.Bottom == parent.Height
|
||||
&& sceneArea.Top >= parent.Height / 3 && Math.Abs(sceneArea.Width / (double)sceneArea.Height
|
||||
- sceneSource.Width / (double)sceneSource.Height) < .01;
|
||||
var lowerDetail = backdrop.GetPixel(parent.Width * 4 / 5, parent.Height * 4 / 5);
|
||||
report["login_lower_scene_visible_in_previously_empty_area"] = Math.Abs(lowerDetail.R - Brand.Surface.R)
|
||||
+ Math.Abs(lowerDetail.G - Brand.Surface.G) + Math.Abs(lowerDetail.B - Brand.Surface.B) > 30;
|
||||
var originCorrect = true;
|
||||
var maximumChannelError = 0;
|
||||
var originPixels = new List<object>();
|
||||
foreach (var point in new[] { P(40, 180), P(220, 300), P(400, 330) })
|
||||
{
|
||||
var background = backdrop.GetPixel(card.Left + point.X, card.Top + point.Y);
|
||||
var actual = moved.GetPixel(point.X, point.Y);
|
||||
var expected = Tint(background);
|
||||
var difference = Math.Max(Math.Abs(actual.R - expected.R),
|
||||
Math.Max(Math.Abs(actual.G - expected.G), Math.Abs(actual.B - expected.B)));
|
||||
maximumChannelError = Math.Max(maximumChannelError, difference);
|
||||
originCorrect &= difference <= 2;
|
||||
originPixels.Add(new { point.X, point.Y, background = background.ToArgb(), actual = actual.ToArgb(), expected = expected.ToArgb(), difference });
|
||||
}
|
||||
report["login_surface_move_pixel_probes"] = originPixels;
|
||||
report["login_surface_move_maximum_channel_error"] = maximumChannelError;
|
||||
report["login_surface_move_keeps_parent_artwork_coordinates"] = originCorrect;
|
||||
}
|
||||
|
||||
private static double Contrast(Color foreground, Color background)
|
||||
{
|
||||
static double Luminance(Color color)
|
||||
{
|
||||
static double Linear(byte value) => value / 255d <= .04045
|
||||
? value / 255d / 12.92 : Math.Pow((value / 255d + .055) / 1.055, 2.4);
|
||||
return .2126 * Linear(color.R) + .7152 * Linear(color.G) + .0722 * Linear(color.B);
|
||||
}
|
||||
var a = Luminance(foreground); var b = Luminance(background);
|
||||
return (Math.Max(a, b) + .05) / (Math.Min(a, b) + .05);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,12 @@ internal sealed class TrafficChart : Control
|
||||
base.OnPaint(e);
|
||||
_timeline.AdvanceClock();
|
||||
var points = VisiblePoints();
|
||||
var peak = points.Length == 0 ? 1024 : Math.Max(1024, points.Max(p => Math.Max(p.Up, p.Down)));
|
||||
var peak = points.Length == 0 ? 1024 : Math.Max(1024, points.Max(p => DisplayedSeries switch
|
||||
{
|
||||
TrafficChartSeries.Upload => p.Up,
|
||||
TrafficChartSeries.Download => p.Down,
|
||||
_ => Math.Max(p.Up, p.Down),
|
||||
}));
|
||||
var axis = ChartAxisY.Create(peak, speed: true);
|
||||
var g = e.Graphics;
|
||||
var scale = DeviceDpi / 96f;
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
<ApplicationIcon>assets\zonghengjia-app-v1.ico</ApplicationIcon>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
|
||||
<Version>0.3.17</Version>
|
||||
<AssemblyVersion>0.3.17.0</AssemblyVersion>
|
||||
<FileVersion>0.3.17.0</FileVersion>
|
||||
<InformationalVersion>0.3.17</InformationalVersion>
|
||||
<Version>0.3.18</Version>
|
||||
<AssemblyVersion>0.3.18.0</AssemblyVersion>
|
||||
<FileVersion>0.3.18.0</FileVersion>
|
||||
<InformationalVersion>0.3.18</InformationalVersion>
|
||||
<Product>纵横家</Product>
|
||||
<Company>优创未来(UCVL)</Company>
|
||||
<Description>纵横家 Windows 智能网络客户端</Description>
|
||||
|
||||
+627
-630
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user