Skip to content

Commit

Permalink
feat: auto toggle show amnezia props
Browse files Browse the repository at this point in the history
closes #401
  • Loading branch information
zaneschepke committed Oct 20, 2024
1 parent 105c753 commit ab7499a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -84,9 +85,14 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
var showApplicationsDialog by remember { mutableStateOf(false) }
var showAuthPrompt by remember { mutableStateOf(false) }
var isAuthenticated by remember { mutableStateOf(false) }
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }

val uiState by viewModel.uiState.collectAsStateWithLifecycle()
var configType by remember { mutableStateOf<ConfigType?>(null) }
val derivedConfigType = remember {
derivedStateOf<ConfigType> {
configType ?: if (!uiState.hasAmneziaProperties()) ConfigType.WIREGUARD else ConfigType.AMNEZIA
}
}
val saved by viewModel.saved.collectAsStateWithLifecycle(null)

LaunchedEffect(saved) {
Expand Down Expand Up @@ -228,7 +234,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
)
ConfigurationToggle(
stringResource(id = R.string.show_amnezia_properties),
checked = configType == ConfigType.AMNEZIA,
checked = derivedConfigType.value == ConfigType.AMNEZIA,
padding = screenPadding,
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
modifier = Modifier.focusRequester(focusRequester),
Expand Down Expand Up @@ -346,7 +352,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
modifier = Modifier.width(IntrinsicSize.Min),
)
}
if (configType == ConfigType.AMNEZIA) {
if (derivedConfigType.value == ConfigType.AMNEZIA) {
ConfigurationTextBox(
value = uiState.interfaceProxy.junkPacketCount,
onValueChange = viewModel::onJunkPacketCountChanged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ data class ConfigUiState(
var tunnelName: String = "",
val isAmneziaEnabled: Boolean = false,
) {
fun hasAmneziaProperties(): Boolean {
return this.interfaceProxy.junkPacketCount != ""
}
companion object {
fun from(config: Config): ConfigUiState {
val proxyPeers = config.peers.map { PeerProxy.from(it) }
Expand Down

0 comments on commit ab7499a

Please sign in to comment.