feat: Enhance logging and debugging capabilities across Protocol and UI components

This commit is contained in:
k1ngsterr1
2026-01-09 00:34:45 +05:00
parent 28a0d7a601
commit 87cee5b9c3
7 changed files with 467 additions and 164 deletions

View File

@@ -124,6 +124,12 @@ fun ChatsListScreen(
// Protocol connection state
val protocolState by ProtocolManager.state.collectAsState()
val debugLogs by ProtocolManager.debugLogs.collectAsState()
// Dev console state
var showDevConsole by remember { mutableStateOf(false) }
var titleClickCount by remember { mutableStateOf(0) }
var lastClickTime by remember { mutableStateOf(0L) }
var visible by remember { mutableStateOf(false) }
@@ -131,6 +137,95 @@ fun ChatsListScreen(
visible = true
}
// Dev console dialog
if (showDevConsole) {
AlertDialog(
onDismissRequest = { showDevConsole = false },
title = {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("Dev Console", fontWeight = FontWeight.Bold)
Text(
text = protocolState.name,
fontSize = 12.sp,
color = when (protocolState) {
ProtocolState.AUTHENTICATED -> Color(0xFF4CAF50)
ProtocolState.CONNECTING, ProtocolState.HANDSHAKING -> Color(0xFFFFA726)
else -> Color(0xFFFF5722)
}
)
}
},
text = {
Column {
Box(
modifier = Modifier
.fillMaxWidth()
.height(400.dp)
.background(Color(0xFF1A1A1A), RoundedCornerShape(8.dp))
.padding(8.dp)
) {
val scrollState = rememberScrollState()
LaunchedEffect(debugLogs.size) {
scrollState.animateScrollTo(scrollState.maxValue)
}
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
) {
if (debugLogs.isEmpty()) {
Text(
"No logs yet...",
color = Color.Gray,
fontSize = 12.sp
)
} else {
debugLogs.forEach { log ->
Text(
text = log,
color = when {
log.contains("") -> Color(0xFF4CAF50)
log.contains("") -> Color(0xFFFF5722)
log.contains("⚠️") -> Color(0xFFFFA726)
log.contains("📤") -> Color(0xFF2196F3)
log.contains("📥") -> Color(0xFF9C27B0)
else -> Color.White
},
fontSize = 11.sp,
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
modifier = Modifier.padding(vertical = 1.dp)
)
}
}
}
}
}
},
confirmButton = {
Row {
TextButton(onClick = { ProtocolManager.clearLogs() }) {
Text("Clear")
}
TextButton(onClick = {
ProtocolManager.connect()
}) {
Text("Reconnect")
}
TextButton(onClick = { showDevConsole = false }) {
Text("Close")
}
}
},
containerColor = if (isDarkTheme) Color(0xFF212121) else Color.White
)
}
// Drawer menu items
val menuItems = listOf(
DrawerMenuItem(
@@ -211,17 +306,73 @@ fun ChatsListScreen(
}
// Menu items
menuItems.forEach { item ->
DrawerItem(
icon = item.icon,
title = item.title,
onClick = {
Column(
modifier = Modifier
.fillMaxHeight()
.weight(1f)
) {
Spacer(modifier = Modifier.height(8.dp))
menuItems.forEachIndexed { index, item ->
DrawerItem(
icon = item.icon,
title = item.title,
onClick = {
scope.launch { drawerState.close() }
item.onClick()
},
isDarkTheme = isDarkTheme
)
// Add separator between items (except after last)
if (index < menuItems.size - 1) {
Divider(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
thickness = 0.5.dp,
color = if (isDarkTheme) Color(0xFF3A3A3A) else Color(0xFFE8E8E8)
)
}
}
}
// Logout button at bottom
Divider(
modifier = Modifier.padding(horizontal = 16.dp),
thickness = 0.5.dp,
color = if (isDarkTheme) Color(0xFF3A3A3A) else Color(0xFFE8E8E8)
)
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp)
.clip(RoundedCornerShape(12.dp))
.background(Color(0x20FF3B30))
.clickable {
scope.launch { drawerState.close() }
item.onClick()
},
isDarkTheme = isDarkTheme
onLogout()
}
.padding(horizontal = 16.dp, vertical = 12.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Icons.Default.Logout,
contentDescription = "Logout",
tint = Color(0xFFFF3B30),
modifier = Modifier.size(24.dp)
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = "Log Out",
fontSize = 16.sp,
fontWeight = FontWeight.Medium,
color = Color(0xFFFF3B30)
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
) {
@@ -247,9 +398,22 @@ fun ChatsListScreen(
}
},
title = {
// Stories / Title area
// Stories / Title area - Triple click to open dev console
Row(
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
val currentTime = System.currentTimeMillis()
if (currentTime - lastClickTime < 500) {
titleClickCount++
if (titleClickCount >= 3) {
showDevConsole = true
titleClickCount = 0
}
} else {
titleClickCount = 1
}
lastClickTime = currentTime
}
) {
// User story avatar placeholder
Box(