Skip to content

Commit cdd28ab

Browse files
committed
Address CodeRabbit feedback: use status constants, fix comments, remove redundant code
1 parent 019bdbe commit cdd28ab

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ private enum TransportProtocol
4747
private Task verificationTask;
4848
private string lastHealthStatus;
4949

50+
// Health status constants
51+
private const string HealthStatusUnknown = "Unknown";
52+
private const string HealthStatusHealthy = "Healthy";
53+
private const string HealthStatusPingFailed = "Ping Failed";
54+
private const string HealthStatusUnhealthy = "Unhealthy";
55+
5056
// Events
5157
public event Action OnManualConfigUpdateRequested;
5258

@@ -175,7 +181,7 @@ public void UpdateConnectionStatus()
175181
statusIndicator.AddToClassList("disconnected");
176182
connectionToggleButton.text = "Start Session";
177183

178-
healthStatusLabel.text = "Unknown";
184+
healthStatusLabel.text = HealthStatusUnknown;
179185
healthIndicator.RemoveFromClassList("healthy");
180186
healthIndicator.RemoveFromClassList("warning");
181187
healthIndicator.AddToClassList("unknown");
@@ -426,17 +432,16 @@ private async Task VerifyBridgeConnectionInternalAsync()
426432
var bridgeService = MCPServiceLocator.Bridge;
427433
if (!bridgeService.IsRunning)
428434
{
429-
healthStatusLabel.text = "Disconnected";
435+
healthStatusLabel.text = HealthStatusUnknown;
430436
healthIndicator.RemoveFromClassList("healthy");
431437
healthIndicator.RemoveFromClassList("warning");
432-
healthIndicator.RemoveFromClassList("unknown");
433438
healthIndicator.AddToClassList("unknown");
434439

435440
// Only log if state changed
436-
if (lastHealthStatus != "Disconnected")
441+
if (lastHealthStatus != HealthStatusUnknown)
437442
{
438443
McpLog.Warn("Cannot verify connection: Bridge is not running");
439-
lastHealthStatus = "Disconnected";
444+
lastHealthStatus = HealthStatusUnknown;
440445
}
441446
return;
442447
}
@@ -450,7 +455,7 @@ private async Task VerifyBridgeConnectionInternalAsync()
450455
string newStatus;
451456
if (result.Success && result.PingSucceeded)
452457
{
453-
newStatus = "Healthy";
458+
newStatus = HealthStatusHealthy;
454459
healthStatusLabel.text = newStatus;
455460
healthIndicator.AddToClassList("healthy");
456461

@@ -463,11 +468,11 @@ private async Task VerifyBridgeConnectionInternalAsync()
463468
}
464469
else if (result.HandshakeValid)
465470
{
466-
newStatus = "Ping Failed";
471+
newStatus = HealthStatusPingFailed;
467472
healthStatusLabel.text = newStatus;
468473
healthIndicator.AddToClassList("warning");
469474

470-
// Always log warnings/errors
475+
// Log once per distinct warning state
471476
if (lastHealthStatus != newStatus)
472477
{
473478
McpLog.Warn($"Connection verification warning: {result.Message}");
@@ -476,11 +481,11 @@ private async Task VerifyBridgeConnectionInternalAsync()
476481
}
477482
else
478483
{
479-
newStatus = "Unhealthy";
484+
newStatus = HealthStatusUnhealthy;
480485
healthStatusLabel.text = newStatus;
481486
healthIndicator.AddToClassList("warning");
482487

483-
// Always log errors
488+
// Log once per distinct error state
484489
if (lastHealthStatus != newStatus)
485490
{
486491
McpLog.Error($"Connection verification failed: {result.Message}");

0 commit comments

Comments
 (0)