Skip to content

Commit cddf9d9

Browse files
committed
feat(home): show SOCKS5 proxy endpoint and auth details in connection status
1 parent 35089c2 commit cddf9d9

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

android/app/src/main/java/com/masterdns/vpn/ui/home/HomeScreen.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import androidx.compose.ui.text.style.TextAlign
2929
import androidx.compose.ui.unit.dp
3030
import androidx.compose.ui.unit.sp
3131
import androidx.hilt.navigation.compose.hiltViewModel
32+
import com.google.gson.Gson
33+
import com.google.gson.reflect.TypeToken
3234
import com.masterdns.vpn.ui.theme.*
3335
import com.masterdns.vpn.util.VpnManager
3436

@@ -43,6 +45,14 @@ fun HomeScreen(
4345
val scanStatus by VpnManager.scanStatus.collectAsState()
4446
val selectedProfile by viewModel.selectedProfile.collectAsState()
4547
val context = LocalContext.current
48+
val advanced = remember(selectedProfile?.advancedJson) {
49+
parseAdvanced(selectedProfile?.advancedJson.orEmpty())
50+
}
51+
val proxyHost = advanced["LISTEN_IP"]?.trim().takeUnless { it.isNullOrEmpty() } ?: "127.0.0.1"
52+
val proxyPort = selectedProfile?.listenPort ?: 18000
53+
val socksAuthEnabled = advanced["SOCKS5_AUTH"].equals("true", ignoreCase = true)
54+
val socksUser = advanced["SOCKS5_USER"]?.trim().orEmpty()
55+
val socksPass = advanced["SOCKS5_PASS"]?.trim().orEmpty()
4656

4757
val vpnPermissionLauncher = rememberLauncherForActivityResult(
4858
ActivityResultContracts.StartActivityForResult()
@@ -275,6 +285,18 @@ fun HomeScreen(
275285
text = "Download: ${formatSpeed(downBps)} Upload: ${formatSpeed(upBps)}",
276286
style = MaterialTheme.typography.bodySmall
277287
)
288+
Spacer(modifier = Modifier.height(8.dp))
289+
Text(
290+
text = "SOCKS5: $proxyHost:$proxyPort",
291+
style = MaterialTheme.typography.bodySmall.copy(fontWeight = FontWeight.SemiBold)
292+
)
293+
if (socksAuthEnabled && socksUser.isNotBlank() && socksPass.isNotBlank()) {
294+
Spacer(modifier = Modifier.height(2.dp))
295+
Text(
296+
text = "Auth: $socksUser / $socksPass",
297+
style = MaterialTheme.typography.bodySmall
298+
)
299+
}
278300
}
279301
}
280302

@@ -350,3 +372,12 @@ private fun formatSpeed(bps: Long): String {
350372
else -> "${bps} B/s"
351373
}
352374
}
375+
376+
private fun parseAdvanced(json: String): Map<String, String> {
377+
return try {
378+
val type = object : TypeToken<Map<String, String>>() {}.type
379+
Gson().fromJson<Map<String, String>>(json, type) ?: emptyMap()
380+
} catch (_: Exception) {
381+
emptyMap()
382+
}
383+
}

0 commit comments

Comments
 (0)