@@ -45,7 +45,6 @@ public AgentViewModel Create(IAgentExpanderHost expanderHost, Uuid id, string fu
4545 string ? workspaceName , bool ? didP2p , string ? preferredDerp , TimeSpan ? latency , TimeSpan ? preferredDerpLatency ,
4646 DateTime ? lastHandshake )
4747 {
48- System . Diagnostics . Debug . WriteLine ( $ "Creating agent: { didP2p } { preferredDerp } { latency } { lastHandshake } ") ;
4948 return new AgentViewModel ( childLogger , coderApiClientFactory , credentialManager , agentAppViewModelFactory ,
5049 expanderHost , id )
5150 {
@@ -88,6 +87,19 @@ public enum AgentConnectionStatus
8887 Offline ,
8988}
9089
90+ public static class AgentConnectionStatusExtensions
91+ {
92+ public static string ToDisplayString ( this AgentConnectionStatus status ) =>
93+ status switch
94+ {
95+ AgentConnectionStatus . Healthy => "Healthy" ,
96+ AgentConnectionStatus . Unhealthy => "High latency" ,
97+ AgentConnectionStatus . NoRecentHandshake => "No recent handshake" ,
98+ AgentConnectionStatus . Offline => "Offline" ,
99+ _ => status . ToString ( )
100+ } ;
101+ }
102+
91103public partial class AgentViewModel : ObservableObject , IModelUpdateable < AgentViewModel >
92104{
93105 private const string DefaultDashboardUrl = "https://coder.com" ;
@@ -169,6 +181,7 @@ public string FullyQualifiedDomainName
169181 [ ObservableProperty ]
170182 [ NotifyPropertyChangedFor ( nameof ( ShowExpandAppsMessage ) ) ]
171183 [ NotifyPropertyChangedFor ( nameof ( ExpandAppsMessage ) ) ]
184+ [ NotifyPropertyChangedFor ( nameof ( ConnectionTooltip ) ) ]
172185 public required partial AgentConnectionStatus ConnectionStatus { get ; set ; }
173186
174187 [ ObservableProperty ]
@@ -214,11 +227,12 @@ public string FullyQualifiedDomainName
214227 public string ConnectionTooltip { get
215228 {
216229 var description = new StringBuilder ( ) ;
230+ var highLatencyWarning = ConnectionStatus == AgentConnectionStatus . Unhealthy ? $ "({ AgentConnectionStatus . Unhealthy . ToDisplayString ( ) } )" : "" ;
217231
218232 if ( DidP2p != null && DidP2p . Value && Latency != null )
219233 {
220234 description . Append ( $ """
221- You're connected peer-to-peer.
235+ You're connected peer-to-peer. { highLatencyWarning }
222236
223237 You ↔ { Latency . Value . Milliseconds } ms ↔ { WorkspaceName }
224238 """
@@ -227,7 +241,7 @@ public string ConnectionTooltip { get
227241 else if ( PreferredDerpLatency != null )
228242 {
229243 description . Append ( $ """
230- You're connected through a DERP relay.
244+ You're connected through a DERP relay. { highLatencyWarning }
231245 We'll switch over to peer-to-peer when available.
232246
233247 Total latency: { PreferredDerpLatency . Value . Milliseconds } ms
@@ -247,15 +261,14 @@ public string ConnectionTooltip { get
247261 }
248262 }
249263 }
264+ else
265+ {
266+ description . Append ( ConnectionStatus . ToDisplayString ( ) ) ;
267+ }
250268 if ( LastHandshake != null )
251- description . Append ( $ "\n \n Last handshake: { LastHandshake ? . ToString ( ) ?? "Unknown" } ") ;
252-
253- var tooltip = description . ToString ( ) . TrimEnd ( '\n ' , ' ' ) ;
254-
255- if ( string . IsNullOrEmpty ( tooltip ) )
256- return "No connection information available." ;
269+ description . Append ( $ "\n \n Last handshake: { LastHandshake ? . ToString ( ) } ") ;
257270
258- return tooltip ;
271+ return description . ToString ( ) . TrimEnd ( ' \n ' , ' ' ) ; ;
259272 }
260273 }
261274
0 commit comments