From 9fb4b3cf406656295566cb2799d602671411a2ef Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 24 Nov 2023 19:38:19 +0400 Subject: [PATCH] desktop: don't show device specific network and database settings when connected to remote host (#3449) --- .../common/views/database/DatabaseView.kt | 182 +++++++++--------- .../views/usersettings/NetworkAndServers.kt | 19 +- 2 files changed, 107 insertions(+), 94 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt index bc43310b8..a4c8dc981 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/database/DatabaseView.kt @@ -40,6 +40,7 @@ fun DatabaseView( m: ChatModel, showSettingsModal: (@Composable (ChatModel) -> Unit) -> (() -> Unit) ) { + val currentRemoteHost by remember { chatModel.currentRemoteHost } val progressIndicator = remember { mutableStateOf(false) } val prefs = m.controller.appPrefs val useKeychain = remember { mutableStateOf(prefs.storeDBPassphrase.get()) } @@ -68,6 +69,7 @@ fun DatabaseView( val user = m.currentUser.value val rhId = user?.remoteHostId DatabaseLayout( + currentRemoteHost = currentRemoteHost, progressIndicator.value, remember { m.chatRunning }.value != false, m.chatDbChanged.value, @@ -119,6 +121,7 @@ fun DatabaseView( @Composable fun DatabaseLayout( + currentRemoteHost: RemoteHostInfo?, progressIndicator: Boolean, runChat: Boolean, chatDbChanged: Boolean, @@ -165,103 +168,107 @@ fun DatabaseLayout( } } ) - SectionDividerSpaced(maxTopPadding = true) - SectionView(stringResource(MR.strings.run_chat_section)) { - RunChatSetting(runChat, stopped, startChat, stopChatAlert) - } - SectionTextFooter( - if (stopped) { - stringResource(MR.strings.you_must_use_the_most_recent_version_of_database) - } else { - stringResource(MR.strings.stop_chat_to_enable_database_actions) + if (currentRemoteHost == null) { + SectionDividerSpaced(maxTopPadding = true) + + SectionView(stringResource(MR.strings.run_chat_section)) { + RunChatSetting(runChat, stopped, startChat, stopChatAlert) } - ) - SectionDividerSpaced() - - SectionView(stringResource(MR.strings.chat_database_section)) { - val unencrypted = chatDbEncrypted == false - SettingsActionItem( - if (unencrypted) painterResource(MR.images.ic_lock_open_right) else if (useKeyChain) painterResource(MR.images.ic_vpn_key_filled) - else painterResource(MR.images.ic_lock), - stringResource(MR.strings.database_passphrase), - click = showSettingsModal() { DatabaseEncryptionView(it) }, - iconColor = if (unencrypted || (appPlatform.isDesktop && passphraseSaved)) WarningOrange else MaterialTheme.colors.secondary, - disabled = operationsDisabled + SectionTextFooter( + if (stopped) { + stringResource(MR.strings.you_must_use_the_most_recent_version_of_database) + } else { + stringResource(MR.strings.stop_chat_to_enable_database_actions) + } ) - if (appPlatform.isDesktop && developerTools) { + SectionDividerSpaced() + + SectionView(stringResource(MR.strings.chat_database_section)) { + val unencrypted = chatDbEncrypted == false SettingsActionItem( - painterResource(MR.images.ic_folder_open), - stringResource(MR.strings.open_database_folder), - ::desktopOpenDatabaseDir, + if (unencrypted) painterResource(MR.images.ic_lock_open_right) else if (useKeyChain) painterResource(MR.images.ic_vpn_key_filled) + else painterResource(MR.images.ic_lock), + stringResource(MR.strings.database_passphrase), + click = showSettingsModal() { DatabaseEncryptionView(it) }, + iconColor = if (unencrypted || (appPlatform.isDesktop && passphraseSaved)) WarningOrange else MaterialTheme.colors.secondary, + disabled = operationsDisabled + ) + if (appPlatform.isDesktop && developerTools) { + SettingsActionItem( + painterResource(MR.images.ic_folder_open), + stringResource(MR.strings.open_database_folder), + ::desktopOpenDatabaseDir, + disabled = operationsDisabled + ) + } + SettingsActionItem( + painterResource(MR.images.ic_ios_share), + stringResource(MR.strings.export_database), + click = { + if (initialRandomDBPassphrase.get()) { + exportProhibitedAlert() + } else { + exportArchive() + } + }, + textColor = MaterialTheme.colors.primary, + iconColor = MaterialTheme.colors.primary, + disabled = operationsDisabled + ) + SettingsActionItem( + painterResource(MR.images.ic_download), + stringResource(MR.strings.import_database), + { withApi { importArchiveLauncher.launch("application/zip") } }, + textColor = Color.Red, + iconColor = Color.Red, + disabled = operationsDisabled + ) + val chatArchiveNameVal = chatArchiveName.value + val chatArchiveTimeVal = chatArchiveTime.value + val chatLastStartVal = chatLastStart.value + if (chatArchiveNameVal != null && chatArchiveTimeVal != null && chatLastStartVal != null) { + val title = chatArchiveTitle(chatArchiveTimeVal, chatLastStartVal) + SettingsActionItem( + painterResource(MR.images.ic_inventory_2), + title, + click = showSettingsModal { ChatArchiveView(it, title, chatArchiveNameVal, chatArchiveTimeVal) }, + disabled = operationsDisabled + ) + } + SettingsActionItem( + painterResource(MR.images.ic_delete_forever), + stringResource(MR.strings.delete_database), + deleteChatAlert, + textColor = Color.Red, + iconColor = Color.Red, disabled = operationsDisabled ) } - SettingsActionItem( - painterResource(MR.images.ic_ios_share), - stringResource(MR.strings.export_database), - click = { - if (initialRandomDBPassphrase.get()) { - exportProhibitedAlert() - } else { - exportArchive() - } - }, - textColor = MaterialTheme.colors.primary, - iconColor = MaterialTheme.colors.primary, - disabled = operationsDisabled - ) - SettingsActionItem( - painterResource(MR.images.ic_download), - stringResource(MR.strings.import_database), - { withApi { importArchiveLauncher.launch("application/zip") }}, - textColor = Color.Red, - iconColor = Color.Red, - disabled = operationsDisabled - ) - val chatArchiveNameVal = chatArchiveName.value - val chatArchiveTimeVal = chatArchiveTime.value - val chatLastStartVal = chatLastStart.value - if (chatArchiveNameVal != null && chatArchiveTimeVal != null && chatLastStartVal != null) { - val title = chatArchiveTitle(chatArchiveTimeVal, chatLastStartVal) - SettingsActionItem( - painterResource(MR.images.ic_inventory_2), - title, - click = showSettingsModal { ChatArchiveView(it, title, chatArchiveNameVal, chatArchiveTimeVal) }, - disabled = operationsDisabled - ) - } - SettingsActionItem( - painterResource(MR.images.ic_delete_forever), - stringResource(MR.strings.delete_database), - deleteChatAlert, - textColor = Color.Red, - iconColor = Color.Red, - disabled = operationsDisabled - ) - } - SectionDividerSpaced(maxTopPadding = true) + SectionDividerSpaced(maxTopPadding = true) - SectionView(stringResource(MR.strings.files_and_media_section).uppercase()) { - val deleteFilesDisabled = operationsDisabled || appFilesCountAndSize.value.first == 0 - SectionItemView( - deleteAppFilesAndMedia, - disabled = deleteFilesDisabled - ) { - Text( - stringResource(if (users.size > 1) MR.strings.delete_files_and_media_for_all_users else MR.strings.delete_files_and_media_all), - color = if (deleteFilesDisabled) MaterialTheme.colors.secondary else Color.Red - ) + SectionView(stringResource(MR.strings.files_and_media_section).uppercase()) { + val deleteFilesDisabled = operationsDisabled || appFilesCountAndSize.value.first == 0 + SectionItemView( + deleteAppFilesAndMedia, + disabled = deleteFilesDisabled + ) { + Text( + stringResource(if (users.size > 1) MR.strings.delete_files_and_media_for_all_users else MR.strings.delete_files_and_media_all), + color = if (deleteFilesDisabled) MaterialTheme.colors.secondary else Color.Red + ) + } } + val (count, size) = appFilesCountAndSize.value + SectionTextFooter( + if (count == 0) { + stringResource(MR.strings.no_received_app_files) + } else { + String.format(stringResource(MR.strings.total_files_count_and_size), count, formatBytes(size)) + } + ) } - val (count, size) = appFilesCountAndSize.value - SectionTextFooter( - if (count == 0) { - stringResource(MR.strings.no_received_app_files) - } else { - String.format(stringResource(MR.strings.total_files_count_and_size), count, formatBytes(size)) - } - ) + SectionBottomSpacer() } } @@ -666,6 +673,7 @@ private fun operationEnded(m: ChatModel, progressIndicator: MutableState Unit) -> (() -> Unit), showCustomModal: (@Composable (ChatModel, () -> Unit) -> Unit) -> (() -> Unit), ) { + val currentRemoteHost by remember { chatModel.currentRemoteHost } // It's not a state, just a one-time value. Shouldn't be used in any state-related situations val netCfg = remember { chatModel.controller.getNetCfg() } val networkUseSocksProxy: MutableState = remember { mutableStateOf(netCfg.useSocksProxy) } @@ -52,6 +52,7 @@ fun NetworkAndServersView( val proxyPort = remember { derivedStateOf { chatModel.controller.appPrefs.networkProxyHostPort.state.value?.split(":")?.lastOrNull()?.toIntOrNull() ?: 9050 } } NetworkAndServersLayout( + currentRemoteHost = currentRemoteHost, developerTools = developerTools, networkUseSocksProxy = networkUseSocksProxy, onionHosts = onionHosts, @@ -150,6 +151,7 @@ fun NetworkAndServersView( } @Composable fun NetworkAndServersLayout( + currentRemoteHost: RemoteHostInfo?, developerTools: Boolean, networkUseSocksProxy: MutableState, onionHosts: MutableState, @@ -172,14 +174,16 @@ fun NetworkAndServersView( SettingsActionItem(painterResource(MR.images.ic_dns), stringResource(MR.strings.xftp_servers), showCustomModal { m, close -> ProtocolServersView(m, m.remoteHostId, ServerProtocol.XFTP, close) }) - UseSocksProxySwitch(networkUseSocksProxy, proxyPort, toggleSocksProxy, showSettingsModal) - UseOnionHosts(onionHosts, networkUseSocksProxy, showSettingsModal, useOnion) - if (developerTools) { - SessionModePicker(sessionMode, showSettingsModal, updateSessionMode) + if (currentRemoteHost == null) { + UseSocksProxySwitch(networkUseSocksProxy, proxyPort, toggleSocksProxy, showSettingsModal) + UseOnionHosts(onionHosts, networkUseSocksProxy, showSettingsModal, useOnion) + if (developerTools) { + SessionModePicker(sessionMode, showSettingsModal, updateSessionMode) + } + SettingsActionItem(painterResource(MR.images.ic_cable), stringResource(MR.strings.network_settings), showSettingsModal { AdvancedNetworkSettingsView(it) }) } - SettingsActionItem(painterResource(MR.images.ic_cable), stringResource(MR.strings.network_settings), showSettingsModal { AdvancedNetworkSettingsView(it) }) } - if (networkUseSocksProxy.value) { + if (currentRemoteHost == null && networkUseSocksProxy.value) { SectionCustomFooter { Column { Text(annotatedStringResource(MR.strings.disable_onion_hosts_when_not_supported)) @@ -448,6 +452,7 @@ private fun showUpdateNetworkSettingsDialog( fun PreviewNetworkAndServersLayout() { SimpleXTheme { NetworkAndServersLayout( + currentRemoteHost = null, developerTools = true, networkUseSocksProxy = remember { mutableStateOf(true) }, proxyPort = remember { mutableStateOf(9050) },