Skip to content

Commit d1b2c7d

Browse files
committed
added connecting state and improved the logic on tooltip generation
1 parent 419dcb2 commit d1b2c7d

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

App/ViewModels/AgentViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public AgentViewModel CreateDummy(IAgentExpanderHost expanderHost, Uuid id,
8282
public enum AgentConnectionStatus
8383
{
8484
Healthy,
85+
Connecting,
8586
Unhealthy,
8687
NoRecentHandshake,
87-
Offline,
88+
Offline
8889
}
8990

9091
public static class AgentConnectionStatusExtensions
@@ -93,6 +94,7 @@ public static string ToDisplayString(this AgentConnectionStatus status) =>
9394
status switch
9495
{
9596
AgentConnectionStatus.Healthy => "Healthy",
97+
AgentConnectionStatus.Connecting => "Connecting",
9698
AgentConnectionStatus.Unhealthy => "High latency",
9799
AgentConnectionStatus.NoRecentHandshake => "No recent handshake",
98100
AgentConnectionStatus.Offline => "Offline",
@@ -224,7 +226,9 @@ public string FullyQualifiedDomainName
224226
[NotifyPropertyChangedFor(nameof(ConnectionTooltip))]
225227
public partial DateTime? LastHandshake { get; set; } = null;
226228

227-
public string ConnectionTooltip { get
229+
public string ConnectionTooltip
230+
{
231+
get
228232
{
229233
var description = new StringBuilder();
230234
var highLatencyWarning = ConnectionStatus == AgentConnectionStatus.Unhealthy ? $"({AgentConnectionStatus.Unhealthy.ToDisplayString()})" : "";

App/ViewModels/TrayWindowViewModel.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,28 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
224224
if (string.IsNullOrWhiteSpace(fqdn))
225225
continue;
226226

227-
#pragma warning disable CS8602 // Protobuf will always set this value, so we can safely dereference them.
228-
var lastHandshakeAgo = DateTime.UtcNow.Subtract(agent.LastHandshake.ToDateTime());
229-
#pragma warning restore CS8602
230-
231-
// For compatibility with older deployments, we assume that if the
232-
// last ping is null, the agent is healthy.
233-
var isLatencyAcceptable = agent.LastPing == null || agent.LastPing.Latency.ToTimeSpan() < HealthyPingThreshold;
234227
var connectionStatus = AgentConnectionStatus.Healthy;
235-
if (lastHandshakeAgo > TimeSpan.FromMinutes(5))
228+
229+
if (agent.LastHandshake != null && agent.LastHandshake.ToDateTime() != default && agent.LastHandshake.ToDateTime() < DateTime.UtcNow)
236230
{
237-
connectionStatus = AgentConnectionStatus.NoRecentHandshake;
231+
// For compatibility with older deployments, we assume that if the
232+
// last ping is null, the agent is healthy.
233+
var isLatencyAcceptable = agent.LastPing == null || agent.LastPing.Latency.ToTimeSpan() < HealthyPingThreshold;
234+
235+
var lastHandshakeAgo = DateTime.UtcNow.Subtract(agent.LastHandshake.ToDateTime());
236+
237+
if (lastHandshakeAgo > TimeSpan.FromMinutes(5))
238+
connectionStatus = AgentConnectionStatus.NoRecentHandshake;
239+
else if (!isLatencyAcceptable)
240+
connectionStatus = AgentConnectionStatus.Unhealthy;
238241
}
239-
else if (!isLatencyAcceptable)
242+
else
240243
{
241-
connectionStatus = AgentConnectionStatus.Unhealthy;
244+
// If the last handshake is not correct (null, default or in the future),
245+
// we assume the agent is connecting (yellow status icon).
246+
connectionStatus = AgentConnectionStatus.Connecting;
242247
}
243248

244-
245249
workspacesWithAgents.Add(agent.WorkspaceId);
246250
var workspace = rpcModel.Workspaces.FirstOrDefault(w => w.Id == agent.WorkspaceId);
247251

@@ -257,7 +261,7 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
257261
agent.LastPing?.PreferredDerp,
258262
agent.LastPing?.Latency?.ToTimeSpan(),
259263
agent.LastPing?.PreferredDerpLatency?.ToTimeSpan(),
260-
agent.LastHandshake?.ToDateTime()));
264+
agent.LastHandshake != null && agent.LastHandshake.ToDateTime() != default ? agent.LastHandshake?.ToDateTime() : null));
261265
}
262266

263267
// For every stopped workspace that doesn't have any agents, add a

App/Views/Pages/TrayWindowMainPage.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
<SolidColorBrush Color="#ffcc01" />
153153
</converters:StringToBrushSelectorItem.Value>
154154
</converters:StringToBrushSelectorItem>
155+
<converters:StringToBrushSelectorItem Key="Connecting">
156+
<converters:StringToBrushSelectorItem.Value>
157+
<SolidColorBrush Color="#ffcc01" />
158+
</converters:StringToBrushSelectorItem.Value>
159+
</converters:StringToBrushSelectorItem>
155160
<converters:StringToBrushSelectorItem Key="Healthy">
156161
<converters:StringToBrushSelectorItem.Value>
157162
<SolidColorBrush Color="#34c759" />

0 commit comments

Comments
 (0)