parent
105c753c66
commit
ab7499a616
|
@ -33,6 +33,7 @@ import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
@ -84,9 +85,14 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
||||||
var showApplicationsDialog by remember { mutableStateOf(false) }
|
var showApplicationsDialog by remember { mutableStateOf(false) }
|
||||||
var showAuthPrompt by remember { mutableStateOf(false) }
|
var showAuthPrompt by remember { mutableStateOf(false) }
|
||||||
var isAuthenticated by remember { mutableStateOf(false) }
|
var isAuthenticated by remember { mutableStateOf(false) }
|
||||||
var configType by remember { mutableStateOf(ConfigType.WIREGUARD) }
|
|
||||||
|
|
||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
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)
|
val saved by viewModel.saved.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
LaunchedEffect(saved) {
|
LaunchedEffect(saved) {
|
||||||
|
@ -228,7 +234,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
||||||
)
|
)
|
||||||
ConfigurationToggle(
|
ConfigurationToggle(
|
||||||
stringResource(id = R.string.show_amnezia_properties),
|
stringResource(id = R.string.show_amnezia_properties),
|
||||||
checked = configType == ConfigType.AMNEZIA,
|
checked = derivedConfigType.value == ConfigType.AMNEZIA,
|
||||||
padding = screenPadding,
|
padding = screenPadding,
|
||||||
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
|
onCheckChanged = { configType = if (it) ConfigType.AMNEZIA else ConfigType.WIREGUARD },
|
||||||
modifier = Modifier.focusRequester(focusRequester),
|
modifier = Modifier.focusRequester(focusRequester),
|
||||||
|
@ -346,7 +352,7 @@ fun ConfigScreen(tunnelId: Int, focusRequester: FocusRequester) {
|
||||||
modifier = Modifier.width(IntrinsicSize.Min),
|
modifier = Modifier.width(IntrinsicSize.Min),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (configType == ConfigType.AMNEZIA) {
|
if (derivedConfigType.value == ConfigType.AMNEZIA) {
|
||||||
ConfigurationTextBox(
|
ConfigurationTextBox(
|
||||||
value = uiState.interfaceProxy.junkPacketCount,
|
value = uiState.interfaceProxy.junkPacketCount,
|
||||||
onValueChange = viewModel::onJunkPacketCountChanged,
|
onValueChange = viewModel::onJunkPacketCountChanged,
|
||||||
|
|
|
@ -18,6 +18,9 @@ data class ConfigUiState(
|
||||||
var tunnelName: String = "",
|
var tunnelName: String = "",
|
||||||
val isAmneziaEnabled: Boolean = false,
|
val isAmneziaEnabled: Boolean = false,
|
||||||
) {
|
) {
|
||||||
|
fun hasAmneziaProperties(): Boolean {
|
||||||
|
return this.interfaceProxy.junkPacketCount != ""
|
||||||
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun from(config: Config): ConfigUiState {
|
fun from(config: Config): ConfigUiState {
|
||||||
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
val proxyPeers = config.peers.map { PeerProxy.from(it) }
|
||||||
|
|
Loading…
Reference in New Issue