Windows 0.3.6 runtime preflight and update download reliability source delta; connection fixes retained; no private history or other platform changes

This commit is contained in:
2026-11-06 15:28:10 +00:00
parent 23a87387b8
commit ac40dd3a6c
18 changed files with 599 additions and 58 deletions
+60 -3
View File
@@ -78,6 +78,8 @@ internal sealed partial class MainForm : Form
private bool _updateCheckRunning;
private DateTimeOffset _nextUpdateCheckAt = DateTimeOffset.MinValue;
private bool _installerLaunched;
private bool _runtimeRepairRequired;
private readonly ToolTip _runtimeRepairTip = new() { AutoPopDelay = 20_000 };
internal bool WindowExitSelfTestPassed { get; private set; }
internal bool NetworkRecoveryFailed { get; private set; }
@@ -489,6 +491,9 @@ internal sealed partial class MainForm : Form
return;
}
if (reconnect && _runtimeRepairRequired) return;
if (!PreflightClientRuntime(suppressDialogs, clearRepair: !reconnect)) return;
ConnectionSelection selection;
try
{
@@ -514,6 +519,7 @@ internal sealed partial class MainForm : Form
foreach (var slug in _failedNodes.Where(p => p.Value <= DateTimeOffset.UtcNow).Select(p => p.Key).ToList()) _failedNodes.Remove(slug);
SetConnectionState(false, "正在连接", selection.Manual ? "正在连接手动指定节点…" : "vpn-ai 正在分配工作节点…");
var replacementStarted = false;
var runtimeFailure = false;
try
{
if (!_connectionAuthorization.AccountIsValid(DateTimeOffset.UtcNow, Environment.TickCount64))
@@ -597,6 +603,7 @@ internal sealed partial class MainForm : Form
break;
}
catch (LocalNetworkException) { throw; }
catch (ClientRuntimeException) { throw; }
catch (TailnetUnavailableException)
{
// Connector cleans up only a core it actually attempted.
@@ -646,6 +653,11 @@ internal sealed partial class MainForm : Form
_notifyIcon.Text = "纵横家 · 已连接";
_notifyIcon.ShowBalloonTip(1800, "纵横家已连接", $"当前线路:{_currentNodeName}", ToolTipIcon.Info);
}
catch (ClientRuntimeException exception)
{
runtimeFailure = true;
HandleClientRuntimeFailure(exception, suppressDialogs);
}
catch (Exception) when (connectionToken.IsCancellationRequested)
{
if (!_exiting) await DisconnectAsync();
@@ -682,12 +694,52 @@ internal sealed partial class MainForm : Form
}
finally
{
if (!_xray.IsRunning && reconnect && !connectionToken.IsCancellationRequested && !string.IsNullOrWhiteSpace(_accessToken)) { _wantConnected = true; _nextReconnect = DateTimeOffset.UtcNow.AddMinutes(2); }
if (!runtimeFailure && !_xray.IsRunning && reconnect && !connectionToken.IsCancellationRequested && !string.IsNullOrWhiteSpace(_accessToken)) { _wantConnected = true; _nextReconnect = DateTimeOffset.UtcNow.AddMinutes(2); }
if (ReferenceEquals(_connectionAttemptCancellation, attemptCancellation)) _connectionAttemptCancellation = null;
SetBusy(false);
}
}
private void HandleClientRuntimeFailure(ClientRuntimeException exception, bool suppressDialogs)
{
var firstNotice = !_runtimeRepairRequired;
_runtimeRepairRequired = true;
AppPaths.WriteLog(exception.Diagnostic);
// Component repair requires the installer, not another node or route.
// A running core retains its existing configuration and network state.
var connected = _xray.IsRunning;
_wantConnected = connected;
_nextReconnect = DateTimeOffset.MaxValue;
_connectionHealth.Invalidate();
_connectionHealth.ResetFailures();
_tailnetReadiness.Reset();
_tailnetReconnectItem.Enabled = false;
_handover.Reset();
SetConnectionState(connected, connected ? "组件需修复 · 保留原连接" : "客户端组件需要修复",
exception.Message.Replace('\n', ' '));
_statusDetail.AccessibleDescription = exception.Message;
_runtimeRepairTip.SetToolTip(_statusDetail, exception.Message);
if (connected) _currentNodeLabel.Text = _currentNodeName ?? _currentNodeSlug ?? "原工作节点";
if (!suppressDialogs) MessageBox.Show(exception.Message, "客户端安装需要修复", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else if (firstNotice) _notifyIcon.ShowBalloonTip(7000, "客户端安装需要修复", exception.Message, ToolTipIcon.Warning);
}
private bool PreflightClientRuntime(bool suppressDialogs, bool clearRepair = false)
{
try
{
_xray.ValidateRuntime();
if (clearRepair)
{
_runtimeRepairRequired = false;
_statusDetail.AccessibleDescription = null;
_runtimeRepairTip.SetToolTip(_statusDetail, null);
}
return true;
}
catch (ClientRuntimeException error) { HandleClientRuntimeFailure(error, suppressDialogs); return false; }
}
private async Task DisconnectAsync(bool cancelPending = true)
{
_wantConnected = false;
@@ -788,6 +840,8 @@ internal sealed partial class MainForm : Form
} finally { _healthChecking = false; }
return;
}
// Keep authorization expiry enforcement above this local repair gate.
if (_runtimeRepairRequired) return;
await CheckUplinkAsync();
if (_uplinkChecking || _handover.Pending || _handover.Settling) return;
if (!_wantConnected || _busy || _xray.IsTransitioning || _healthChecking || _exiting || DateTimeOffset.UtcNow < _nextReconnect) return;
@@ -801,6 +855,7 @@ internal sealed partial class MainForm : Form
var revision = _connectionHealth.Revision;
var testedCore = _xray.CoreId;
var health = await _xray.CheckHealthWithRepairAsync(_lifetime.Token);
if (_runtimeRepairRequired) return;
var healthy = health.Healthy;
var decision = _connectionHealth.Observe(revision, testedCore, _xray.CoreId,
_wantConnected, _busy, _xray.IsTransitioning, _exiting, healthy, Environment.TickCount64, health.ProxyHealthy,
@@ -836,6 +891,7 @@ internal sealed partial class MainForm : Form
}
ConnectionAcceptanceTrace.Record("health_failed", _currentNodeSlug, _xray.IsRunning, _xray.CoreId, _connectionHealth.Failures);
if (decision != ConnectionHealthPolicy.Decision.Switch) return;
if (!PreflightClientRuntime(suppressDialogs: true)) return;
if (_currentNodeSlug is not null)
{
if (_currentNodeUsesTailnet)
@@ -935,11 +991,11 @@ internal sealed partial class MainForm : Form
private void ShowAiStatus(string message)
{
if (_exiting || IsDisposed || Disposing) return;
if (_runtimeRepairRequired || _exiting || IsDisposed || Disposing) return;
var reportingCore = _xray.CoreId;
PostUi(() =>
{
if (_dashboardView.Visible && _wantConnected && _xray.CoreId == reportingCore)
if (!_runtimeRepairRequired && _dashboardView.Visible && _wantConnected && _xray.CoreId == reportingCore)
_statusDetail.Text = NodePresentation.LearningDetail(_selectionUiConnected, _currentNodeName, message);
});
}
@@ -1257,6 +1313,7 @@ internal sealed partial class MainForm : Form
_api.Dispose();
_notifyIcon.Visible = false;
_notifyIcon.Dispose();
_runtimeRepairTip.Dispose();
}
protected override void WndProc(ref Message message)