2026-11-13 10:35:04 +08:00
|
|
|
namespace UCVL.VPNPlus;
|
2026-11-03 15:15:23 +00:00
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
private readonly DashboardCombo _connectionModeCombo = new();
|
|
|
|
|
private readonly DashboardCombo _manualNodeCombo = new();
|
|
|
|
|
private bool _selectionUiConnected;
|
|
|
|
|
private int _publicNodeCount;
|
|
|
|
|
private readonly TailnetPreference _tailnetPreference = new();
|
|
|
|
|
private bool _currentNodeUsesTailnet;
|
|
|
|
|
private string? _currentNodeBaseName;
|
|
|
|
|
private string? _transportRetryNodeSlug;
|
|
|
|
|
private IReadOnlyList<PrivateAuxiliaryNode> _privateAuxiliaryNodes = [];
|
|
|
|
|
private PrivateAuxiliaryNode? _currentPrivateEndpoint;
|
|
|
|
|
private bool ManualSelection => _connectionModeCombo.SelectedIndex == 1;
|
|
|
|
|
|
|
|
|
|
private void UpdateConnectedTransportPresentation(bool usesTailnet)
|
|
|
|
|
{
|
|
|
|
|
_currentNodeUsesTailnet = usesTailnet;
|
|
|
|
|
_currentNodeName = _currentNodeBaseName is null ? null
|
|
|
|
|
: NodePresentation.WithTransport(_currentNodeBaseName, _currentNodeUsesTailnet);
|
|
|
|
|
SetTailnetTrafficVisibility(usesTailnet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BuildConnectionSelection()
|
|
|
|
|
{
|
|
|
|
|
ConfigureCombo(_connectionModeCombo, Point.Empty, new(130, 28));
|
|
|
|
|
ConfigureCombo(_manualNodeCombo, Point.Empty, new(240, 28));
|
|
|
|
|
_connectionModeCombo.Font = Brand.Font(8.5f);
|
|
|
|
|
_connectionModeCombo.AccessibleName = "连接方式(断开后可更改)";
|
|
|
|
|
_manualNodeCombo.AccessibleName = "手动选择授权节点(断开后可更改)";
|
|
|
|
|
_connectionModeCombo.Items.AddRange(["AI 自动调度", "手动选择"]);
|
|
|
|
|
_connectionModeCombo.SelectedIndex = 0;
|
|
|
|
|
_connectionModeCombo.SelectedIndexChanged += (_, _) => RefreshSelectionControls();
|
|
|
|
|
_manualNodeCombo.SelectedIndexChanged += (_, _) => RefreshSelectionControls();
|
|
|
|
|
_nodeCard.Controls.AddRange([_connectionModeCombo, _manualNodeCombo]);
|
|
|
|
|
RefreshSelectionControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateSelectionNodes(Profile profile, bool preserveSelections)
|
|
|
|
|
{
|
|
|
|
|
var previous = preserveSelections ? (_manualNodeCombo.SelectedItem as NodeInfo)?.Slug : null;
|
|
|
|
|
if (!preserveSelections) _connectionModeCombo.SelectedIndex = 0;
|
|
|
|
|
_manualNodeCombo.BeginUpdate();
|
|
|
|
|
_manualNodeCombo.Items.Clear();
|
|
|
|
|
_publicNodeCount = profile.Nodes.Count;
|
|
|
|
|
_privateAuxiliaryNodes = PrivateAuxiliaryRouting.Eligible(profile, DateTimeOffset.UtcNow);
|
|
|
|
|
foreach (var node in _privateAuxiliaryNodes) _manualNodeCombo.Items.Add(node);
|
|
|
|
|
foreach (var node in profile.Nodes) _manualNodeCombo.Items.Add(node);
|
|
|
|
|
_availableNodeCount = _manualNodeCombo.Items.Count;
|
|
|
|
|
_manualNodeCombo.SelectedItem = _manualNodeCombo.Items.Cast<NodeInfo>().FirstOrDefault(n => n.Slug == previous);
|
|
|
|
|
_manualNodeCombo.EndUpdate();
|
|
|
|
|
RefreshSelectionControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshSelectionControls()
|
|
|
|
|
{
|
|
|
|
|
var editable = !_busy && !_selectionUiConnected && !_wantConnected && !_xray.IsRunning && !_handoverOperating;
|
|
|
|
|
_connectionModeCombo.Enabled = editable;
|
|
|
|
|
_manualNodeCombo.Enabled = editable;
|
|
|
|
|
_manualNodeCombo.Visible = ManualSelection && editable;
|
|
|
|
|
_currentNodeLabel.Visible = true;
|
|
|
|
|
// The selector already shows AI/manual mode. Give the real connected
|
|
|
|
|
// node name the whole row instead of truncating it beside a duplicate badge.
|
|
|
|
|
_scheduleBadge.Visible = false;
|
|
|
|
|
_scheduleBadge.Text = ManualSelection ? "手动固定" : "AI 自动调度";
|
|
|
|
|
if (!_selectionUiConnected) _currentNodeLabel.Text = "未连接";
|
|
|
|
|
if (editable)
|
|
|
|
|
{
|
|
|
|
|
_currentNodeLabel.Text = "未连接";
|
2026-11-13 10:35:04 +08:00
|
|
|
if (_availableNodeCount > 0 && _statusTitle.Text == "未连接")
|
2026-11-03 15:15:23 +00:00
|
|
|
_statusDetail.Text = ManualSelection
|
|
|
|
|
? "手动选择节点后连接;不可用时不会自动换节点"
|
|
|
|
|
: _privateAuxiliaryNodes.Count > 0 ? "先检测济南办私有节点;不可用时自动选择公共节点" : "点击连接,AI 自动选择工作节点";
|
|
|
|
|
}
|
|
|
|
|
if (_selectionUiConnected && !string.IsNullOrWhiteSpace(_currentNodeName))
|
|
|
|
|
_currentNodeLabel.Text = _currentNodeName;
|
|
|
|
|
_routeCombo.Enabled = editable;
|
|
|
|
|
_routeCombo.Visible = true;
|
|
|
|
|
_routeReadOnly.Visible = true;
|
|
|
|
|
_routeReadOnly.Text = _selectionUiConnected ? _routeCombo.Text : "未生效";
|
|
|
|
|
LayoutDashboard();
|
|
|
|
|
}
|
|
|
|
|
}
|