fix: androidtv multiple tunnel control

Fixes a bug where androidTV was only allowing control of a single tunnel.
Closes #268
This commit is contained in:
Zane Schepke 2024-07-27 06:04:25 -04:00
parent ac18ac8274
commit 547686069f
3 changed files with 20 additions and 7 deletions

View File

@ -134,7 +134,7 @@ jobs:
- name: On nightly release - name: On nightly release
if: ${{ contains(env.TAG_NAME, 'nightly') }} if: ${{ contains(env.TAG_NAME, 'nightly') }}
run: | 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 gh release delete nightly --yes || true
# Setup TAG_NAME, which is used as a general "name" # Setup TAG_NAME, which is used as a general "name"

View File

@ -15,6 +15,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip 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.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
@ -31,11 +33,12 @@ fun RowListItem(
onClick: () -> Unit, onClick: () -> Unit,
rowButton: @Composable () -> Unit, rowButton: @Composable () -> Unit,
expanded: Boolean, expanded: Boolean,
statistics: TunnelStatistics? statistics: TunnelStatistics?,
focusRequester: FocusRequester,
) { ) {
Box( Box(
modifier = modifier =
Modifier Modifier.focusRequester(focusRequester)
.animateContentSize() .animateContentSize()
.clip(RoundedCornerShape(30.dp)) .clip(RoundedCornerShape(30.dp))
.combinedClickable( .combinedClickable(

View File

@ -489,6 +489,7 @@ fun MainScreen(
} }
item { item {
if (uiState.settings.isAutoTunnelEnabled) { if (uiState.settings.isAutoTunnelEnabled) {
val itemFocusRequester = remember { FocusRequester() }
val autoTunnelingLabel = buildAnnotatedString { val autoTunnelingLabel = buildAnnotatedString {
append(stringResource(id = R.string.auto_tunneling)) append(stringResource(id = R.string.auto_tunneling))
append(": ") append(": ")
@ -516,22 +517,29 @@ fun MainScreen(
rowButton = { rowButton = {
if (uiState.settings.isAutoTunnelPaused) { if (uiState.settings.isAutoTunnelPaused) {
TextButton( TextButton(
modifier = Modifier.focusRequester(itemFocusRequester),
onClick = { viewModel.resumeAutoTunneling() }, onClick = { viewModel.resumeAutoTunneling() },
) { ) {
Text(stringResource(id = R.string.resume)) Text(stringResource(id = R.string.resume))
} }
} else { } else {
TextButton( TextButton(
modifier = Modifier.focusRequester(itemFocusRequester),
onClick = { viewModel.pauseAutoTunneling() }, onClick = { viewModel.pauseAutoTunneling() },
) { ) {
Text(stringResource(id = R.string.pause)) Text(stringResource(id = R.string.pause))
} }
} }
}, },
onClick = {}, onClick = {
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
itemFocusRequester.requestFocus()
}
},
onHold = {}, onHold = {},
expanded = false, expanded = false,
statistics = null, statistics = null,
focusRequester = focusRequester
) )
} }
} }
@ -562,6 +570,7 @@ fun MainScreen(
} else { } else {
Color.Gray Color.Gray
}) })
val itemFocusRequester = remember { FocusRequester() }
val expanded = remember { mutableStateOf(false) } val expanded = remember { mutableStateOf(false) }
RowListItem( RowListItem(
icon = { icon = {
@ -607,11 +616,12 @@ fun MainScreen(
} }
} else { } else {
selectedTunnel = tunnel selectedTunnel = tunnel
focusRequester.requestFocus() itemFocusRequester.requestFocus()
} }
}, },
statistics = uiState.vpnState.statistics, statistics = uiState.vpnState.statistics,
expanded = expanded.value, expanded = expanded.value,
focusRequester = focusRequester,
rowButton = { rowButton = {
if ( if (
tunnel.id == selectedTunnel?.id && tunnel.id == selectedTunnel?.id &&
@ -667,7 +677,7 @@ fun MainScreen(
@Composable @Composable
fun TunnelSwitch() = fun TunnelSwitch() =
Switch( Switch(
modifier = Modifier.focusRequester(focusRequester), modifier = Modifier.focusRequester(itemFocusRequester),
checked = checked, checked = checked,
onCheckedChange = { checked -> onCheckedChange = { checked ->
if (!checked) expanded.value = false if (!checked) expanded.value = false
@ -678,7 +688,7 @@ fun MainScreen(
Row { Row {
IconButton( IconButton(
onClick = { onClick = {
if (uiState.settings.isAutoTunnelEnabled) { if (uiState.settings.isAutoTunnelEnabled && !uiState.settings.isAutoTunnelPaused) {
appViewModel.showSnackbarMessage( appViewModel.showSnackbarMessage(
context.getString(R.string.turn_off_auto), context.getString(R.string.turn_off_auto),
) )