From 547686069fd5e018f32aa8cb6e80b4959e17f28f Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Sat, 27 Jul 2024 06:04:25 -0400 Subject: [PATCH] fix: androidtv multiple tunnel control Fixes a bug where androidTV was only allowing control of a single tunnel. Closes #268 --- .github/workflows/release.yml | 2 +- .../ui/common/RowListItem.kt | 7 +++++-- .../ui/screens/main/MainScreen.kt | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5165210..4137721 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,7 +134,7 @@ jobs: - name: On nightly release if: ${{ contains(env.TAG_NAME, 'nightly') }} run: | - echo "RELEASE_NOTES=Nightly build of the latest development version of the android client." >> $GITHUB_ENV + echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV gh release delete nightly --yes || true # Setup TAG_NAME, which is used as a general "name" diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/RowListItem.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/RowListItem.kt index db2dade..1cfd7d0 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/RowListItem.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/RowListItem.kt @@ -15,6 +15,8 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -31,11 +33,12 @@ fun RowListItem( onClick: () -> Unit, rowButton: @Composable () -> Unit, expanded: Boolean, - statistics: TunnelStatistics? + statistics: TunnelStatistics?, + focusRequester: FocusRequester, ) { Box( modifier = - Modifier + Modifier.focusRequester(focusRequester) .animateContentSize() .clip(RoundedCornerShape(30.dp)) .combinedClickable( diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt index e142d93..afdc099 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt @@ -489,6 +489,7 @@ fun MainScreen( } item { if (uiState.settings.isAutoTunnelEnabled) { + val itemFocusRequester = remember { FocusRequester() } val autoTunnelingLabel = buildAnnotatedString { append(stringResource(id = R.string.auto_tunneling)) append(": ") @@ -516,22 +517,29 @@ fun MainScreen( rowButton = { if (uiState.settings.isAutoTunnelPaused) { TextButton( + modifier = Modifier.focusRequester(itemFocusRequester), onClick = { viewModel.resumeAutoTunneling() }, ) { Text(stringResource(id = R.string.resume)) } } else { TextButton( + modifier = Modifier.focusRequester(itemFocusRequester), onClick = { viewModel.pauseAutoTunneling() }, ) { Text(stringResource(id = R.string.pause)) } } }, - onClick = {}, + onClick = { + if (WireGuardAutoTunnel.isRunningOnAndroidTv()) { + itemFocusRequester.requestFocus() + } + }, onHold = {}, expanded = false, statistics = null, + focusRequester = focusRequester ) } } @@ -562,6 +570,7 @@ fun MainScreen( } else { Color.Gray }) + val itemFocusRequester = remember { FocusRequester() } val expanded = remember { mutableStateOf(false) } RowListItem( icon = { @@ -607,11 +616,12 @@ fun MainScreen( } } else { selectedTunnel = tunnel - focusRequester.requestFocus() + itemFocusRequester.requestFocus() } }, statistics = uiState.vpnState.statistics, expanded = expanded.value, + focusRequester = focusRequester, rowButton = { if ( tunnel.id == selectedTunnel?.id && @@ -667,7 +677,7 @@ fun MainScreen( @Composable fun TunnelSwitch() = Switch( - modifier = Modifier.focusRequester(focusRequester), + modifier = Modifier.focusRequester(itemFocusRequester), checked = checked, onCheckedChange = { checked -> if (!checked) expanded.value = false @@ -678,7 +688,7 @@ fun MainScreen( Row { IconButton( onClick = { - if (uiState.settings.isAutoTunnelEnabled) { + if (uiState.settings.isAutoTunnelEnabled && !uiState.settings.isAutoTunnelPaused) { appViewModel.showSnackbarMessage( context.getString(R.string.turn_off_auto), )