Add Android autosocket protocol selection to network settings
This commit is contained in:
1 parent
eda65ece52
commit
9d465bce16
3 files changed
+35
No files matched your search
@@ -44,6 +44,7 @@ import com.utun.chat.data.CallVideoBitrateRange
|
||||
import com.utun.chat.data.MicrophonePermission
|
||||
import com.utun.chat.data.LogManager
|
||||
import com.utun.chat.data.ServerEntry
|
||||
import com.utun.chat.data.AutoSocketProtocols
|
||||
import com.utun.chat.data.LocalSocketState
|
||||
import com.utun.chat.ui.components.LocalSocketNatInfo
|
||||
import com.utun.chat.data.VoiceSettings
|
||||
@@ -261,6 +262,8 @@ private fun DeveloperSettingsTab(vm: ChatViewModel, onDirty: (Boolean) -> Unit,
|
||||
var servers by remember { mutableStateOf<List<ServerEntry>>(emptyList()) }
|
||||
var availableIfaces by remember { mutableStateOf<List<Pair<String, String>>>(emptyList()) }
|
||||
var connectionMode by remember { mutableStateOf("manual") }
|
||||
var autoSocketProtocols by remember { mutableStateOf(AutoSocketProtocols.BOTH) }
|
||||
var savingSocketProtocols by remember { mutableStateOf(false) }
|
||||
var autoConnect by remember { mutableStateOf(true) }
|
||||
|
||||
val localSocketStates by vm.localSockets.collectAsState()
|
||||
@@ -290,6 +293,7 @@ private fun DeveloperSettingsTab(vm: ChatViewModel, onDirty: (Boolean) -> Unit,
|
||||
servers = provider.loadServersFromConfig()
|
||||
availableIfaces = allIface.drop(1)
|
||||
connectionMode = provider.getConnectionMode()
|
||||
autoSocketProtocols = provider.getAutoSocketProtocols()
|
||||
autoConnect = provider.getInt("chat.group_autoconnect") != 0
|
||||
}
|
||||
|
||||
@@ -393,6 +397,35 @@ private fun DeveloperSettingsTab(vm: ChatViewModel, onDirty: (Boolean) -> Unit,
|
||||
}
|
||||
|
||||
if (connectionMode == "auto") {
|
||||
item(key = "auto-socket-protocols") {
|
||||
Column {
|
||||
Text(stringResource(R.string.socket_protocols), style = MaterialTheme.typography.bodyMedium)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
AutoSocketProtocols.values().forEach { protocols ->
|
||||
FilterChip(selected = autoSocketProtocols == protocols, enabled = !savingSocketProtocols,
|
||||
onClick = {
|
||||
if (autoSocketProtocols != protocols) {
|
||||
savingSocketProtocols = true
|
||||
scope.launch {
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
provider.setAutoSocketProtocols(protocols)
|
||||
if (NativeLib.isReady() && !NativeLib.restart(provider.getString("db.path") ?: "",
|
||||
provider.getInt("control.port"), provider.buildConfigText()))
|
||||
LogManager.addLog("ERROR", "CFG", "restart after socket protocol change failed")
|
||||
}
|
||||
autoSocketProtocols = protocols
|
||||
} catch (e: CancellationException) { throw e
|
||||
} catch (e: Exception) {
|
||||
LogManager.addLog("ERROR", "CFG", "socket protocol change failed: ${e.message}")
|
||||
} finally { savingSocketProtocols = false }
|
||||
}
|
||||
}
|
||||
}, label = { Text(protocols.configValue.uppercase()) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Auto mode: read-only live socket display */
|
||||
if (localSocketStates.isEmpty()) {
|
||||
item(key = "no-sockets") { Text(stringResource(R.string.no_sockets), color = MaterialTheme.colorScheme.onSurfaceVariant) }
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
<string name="generate_keys">"Создать ключи"</string>
|
||||
<string name="clear_db">"Очистить БД"</string>
|
||||
<string name="network_interfaces">"Сетевые интерфейсы"</string>
|
||||
<string name="socket_protocols">"Тип сокетов"</string>
|
||||
<string name="automatic">"Авто"</string>
|
||||
<string name="manual">"Вручную"</string>
|
||||
<string name="no_sockets">"Сокеты не обнаружены"</string>
|
||||
|
||||
@@ -268,6 +268,7 @@
|
||||
<string name="generate_keys">"Generate keys"</string>
|
||||
<string name="clear_db">"Clear DB"</string>
|
||||
<string name="network_interfaces">"Network interfaces"</string>
|
||||
<string name="socket_protocols">"Socket protocols"</string>
|
||||
<string name="automatic">"Auto"</string>
|
||||
<string name="manual">"Manual"</string>
|
||||
<string name="no_sockets">"No sockets detected"</string>
|
||||
|
||||
Reference in new issue
Block a user