From ffd37880cf9fa37e2d036efd30ef75a0896e57da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 13 Jun 2026 21:28:47 +0800 Subject: [PATCH] Improve Tailscale View --- .../screen/tools/TailscalePeerScreen.kt | 42 ++++++++++++++++++- .../screen/tools/TailscalePingViewModel.kt | 8 +++- app/src/main/res/values-fa/strings.xml | 10 +++++ app/src/main/res/values-ru-rRU/strings.xml | 10 +++++ app/src/main/res/values-zh-rCN/strings.xml | 10 +++++ app/src/main/res/values-zh-rTW/strings.xml | 10 +++++ app/src/main/res/values/strings.xml | 4 ++ 7 files changed, 91 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePeerScreen.kt b/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePeerScreen.kt index 91c1e45..d8ad4ea 100644 --- a/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePeerScreen.kt +++ b/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePeerScreen.kt @@ -30,6 +30,7 @@ import androidx.compose.material.icons.filled.Terminal import androidx.compose.material.icons.outlined.ContentCopy import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -337,6 +338,20 @@ fun TailscalePeerScreen( fontWeight = FontWeight.Bold, ) } + if (pingState.isDirect && pingState.endpoint.isNotEmpty()) { + Spacer(modifier = Modifier.height(8.dp)) + DetailRow( + label = stringResource(R.string.tailscale_ping_endpoint), + value = pingState.endpoint, + ) + } + if (!pingState.isDirect && pingState.derpRegionCode.isNotEmpty()) { + Spacer(modifier = Modifier.height(8.dp)) + DetailRow( + label = stringResource(R.string.tailscale_ping_derp_region), + value = pingState.derpRegionCode, + ) + } if (pingState.isRunning && pingState.latencyHistory.size > 1) { Spacer(modifier = Modifier.height(8.dp)) Row( @@ -386,9 +401,32 @@ fun TailscalePeerScreen( } } } - } else { + } + if (pingState.error.isNotEmpty()) { + if (pingState.hasResult) { + Spacer(modifier = Modifier.height(8.dp)) + } Text( - text = "No data", + text = pingState.error, + color = MaterialTheme.colorScheme.error, + ) + } else if (pingState.isRunning && !pingState.hasResult) { + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + CircularProgressIndicator( + modifier = Modifier.size(16.dp), + strokeWidth = 2.dp, + ) + Spacer(modifier = Modifier.width(8.dp)) + Text( + text = stringResource(R.string.tailscale_ping_connecting), + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } else if (!pingState.hasResult) { + Text( + text = stringResource(R.string.tailscale_ping_no_data), color = MaterialTheme.colorScheme.onSurfaceVariant, ) } diff --git a/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePingViewModel.kt b/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePingViewModel.kt index d9c3d5d..b87e29f 100644 --- a/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePingViewModel.kt +++ b/app/src/main/java/io/nekohasekai/sfa/compose/screen/tools/TailscalePingViewModel.kt @@ -17,6 +17,7 @@ data class TailscalePingState( val isDirect: Boolean = false, val derpRegionCode: String = "", val endpoint: String = "", + val error: String = "", val latencyHistory: List = emptyList(), ) @@ -31,6 +32,7 @@ class TailscalePingViewModel : BaseViewModel() { copy( isRunning = true, hasResult = false, + error = "", latencyHistory = emptyList(), ) } @@ -47,7 +49,10 @@ class TailscalePingViewModel : BaseViewModel() { result ?: return viewModelScope.launch { if (!currentState.isRunning) return@launch - if (result.error.isNotEmpty()) return@launch + if (result.error.isNotEmpty()) { + updateState { copy(error = result.error) } + return@launch + } val newHistory = currentState.latencyHistory.toMutableList() newHistory.add(result.latencyMs.toFloat()) if (newHistory.size > maxHistorySize) { @@ -60,6 +65,7 @@ class TailscalePingViewModel : BaseViewModel() { isDirect = result.isDirect, derpRegionCode = result.derpRegionCode, endpoint = result.endpoint, + error = "", latencyHistory = newHistory, ) } diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index a7f58fb..22d699b 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -465,6 +465,7 @@ باز کردن لینک احراز هویت نمایش QR کد لینک احراز هویت این دستگاه + خروج از حساب متصل متصل نیست آدرس‌های Tailscale @@ -472,6 +473,15 @@ انقضای کلید گره خروجی فعال + پینگ + شروع + توقف + اتصال مستقیم + اتصال از طریق DERP + نقطه پایانی + منطقه DERP + در حال اتصال… + بدون داده به اشتراک گذاشته شده منقضی شده انقضا %1$s diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 6f5a4fe..69b9b8e 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -471,6 +471,7 @@ Открыть URL авторизации Показать QR-код авторизации Это устройство + Выйти Подключено Не подключено Адреса Tailscale @@ -478,6 +479,15 @@ Срок действия ключа Выходной узел Активен + Пинг + Начать + Остановить + Прямое соединение + Соединение через DERP + Конечная точка + Регион DERP + Подключение… + Нет данных Поделено Истёк Истекает %1$s diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index b45adbc..e48d8b2 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -462,6 +462,7 @@ 打开认证链接 显示认证链接二维码 此设备 + 登出 已连接 未连接 Tailscale 地址 @@ -469,6 +470,15 @@ 密钥过期 出口节点 活跃 + Ping + 启动 + 停止 + 直接连接 + DERP 中继连接 + 端点 + DERP 区域 + 连接中… + 无数据 共享至此 已过期 %1$s过期 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e44e574..611aaf5 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -465,6 +465,7 @@ 開啟認證連結 顯示認證連結 QR 碼 此裝置 + 登出 已連線 未連線 Tailscale 位址 @@ -472,6 +473,15 @@ 金鑰到期 出口節點 活躍 + Ping + 啟動 + 停止 + 直接連線 + DERP 中繼連線 + 端點 + DERP 區域 + 連線中… + 無資料 共享至此 已過期 %1$s過期 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 20c5f5f..0e68738 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -483,6 +483,10 @@ Stop Direct connection DERP-relayed connection + Endpoint + DERP region + Connecting… + No data Shared in Expired Expires %1$s