A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
fix(settings): surface a port forward that was only half added
ExTvc04c70e247f9
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.ktindex 3bc348b..2661a0d 100644--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt@@ -124,6 +124,7 @@ fun SettingsScreen(val portForwardRules by viewModel.portForwardRules.collectAsStateWithLifecycle()val vmState by viewModel.vmState.collectAsStateWithLifecycle()val exportError by viewModel.exportError.collectAsStateWithLifecycle()+ val portForwardPartialWarning by viewModel.portForwardPartialWarning.collectAsStateWithLifecycle()val usbPassthrough by viewModel.usbPassthroughEnabled.collectAsStateWithLifecycle()val autostartOnBoot by viewModel.autostartOnBoot.collectAsStateWithLifecycle()@@ -168,6 +169,11 @@ fun SettingsScreen(snackbarHostState.showSnackbar(msg)viewModel.clearExportError()}+ LaunchedEffect(portForwardPartialWarning) {+ val msg = portForwardPartialWarning ?: return@LaunchedEffect+ snackbarHostState.showSnackbar(msg)+ viewModel.clearPortForwardPartialWarning()+ }Scaffold(topBar = {diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.ktindex 40d063e..26139d5 100644--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt@@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelimport androidx.lifecycle.viewModelScopeimport com.excp.podroid.BuildConfigimport com.excp.podroid.R+import com.excp.podroid.data.repository.AddRuleResultimport com.excp.podroid.data.repository.LanguageManagerimport com.excp.podroid.data.repository.PortForwardRepositoryimport com.excp.podroid.data.repository.PortForwardRule@@ -300,8 +301,18 @@ class SettingsViewModel @Inject constructor(}if (toAdd.isEmpty()) return falseviewModelScope.launch {- toAdd.forEach { proto ->- portForwardRepository.addRule(PortForwardRule(hostPort, guestPort, proto))+ // "both" can add TCP then hit the table ceiling on UDP (or vice+ // versa): the dialog already closed on the true return below, so+ // that partial outcome would otherwise vanish silently.+ val notAdded = toAdd.filter { proto ->+ portForwardRepository.addRule(PortForwardRule(hostPort, guestPort, proto)) != AddRuleResult.ADDED+ }+ if (notAdded.isNotEmpty() && notAdded.size < toAdd.size) {+ _portForwardPartialWarning.value = context.getString(+ R.string.port_forward_partial_add,+ hostPort,+ notAdded.joinToString(", ") { it.uppercase() },+ )}}return true@@ -331,6 +342,14 @@ class SettingsViewModel @Inject constructor(fun clearExportError() { _exportError.value = null }+ private val _portForwardPartialWarning = MutableStateFlow<String?>(null)+ /** One-shot warning when a "both" add only added one protocol (e.g. the+ * table filled between the TCP and UDP rule); clear after showing with+ * [clearPortForwardPartialWarning]. */+ val portForwardPartialWarning: StateFlow<String?> = _portForwardPartialWarning.asStateFlow()++ fun clearPortForwardPartialWarning() { _portForwardPartialWarning.value = null }+fun removePortForward(rule: PortForwardRule) {viewModelScope.launch { portForwardRepository.removeRule(rule) }}diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xmlindex ef69c4a..bccc6ba 100644--- a/app/src/main/res/values-zh/strings.xml+++ b/app/src/main/res/values-zh/strings.xml@@ -121,6 +121,7 @@<string name="port_already_forwarded">端口 %1$d (%2$s) 已转发</string><string name="port_reserved">端口 %1$d 已保留给应用内桌面</string><string name="port_forward_table_full">端口转发已达上限 %1$d 条,请先删除一条。</string>+ <string name="port_forward_partial_add">端口 %1$d:%2$s 未能添加,端口转发数量已达上限。</string><string name="reset">重置</string><string name="remove">删除</string><string name="port_forward_purpose_ssh">SSH</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 1489fe3..53b4979 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -121,6 +121,7 @@<string name="port_already_forwarded">Port %1$d (%2$s) is already forwarded</string><string name="port_reserved">Port %1$d is reserved for the in-app desktop</string><string name="port_forward_table_full">Limit of %1$d port forwards reached. Remove one first.</string>+ <string name="port_forward_partial_add">Port %1$d: %2$s could not be added, the port forward limit was reached.</string><string name="reset">Reset</string><string name="remove">Remove</string><string name="port_forward_purpose_ssh">SSH</string>