diff --git a/_locales/_untranslated_en.json b/_locales/_untranslated_en.json index 7021035cec..a2ad9e0cd4 100644 --- a/_locales/_untranslated_en.json +++ b/_locales/_untranslated_en.json @@ -53,7 +53,7 @@ "prevent_dialog_spam_checkbox": { "message": "Don't allow the app to open this dialog again" }, - "react_more_emojis" : { + "react_more_emojis": { "message": "More emojis..." }, "edit_channel": { diff --git a/packages/frontend/scss/login/_login.scss b/packages/frontend/scss/login/_login.scss index 0ea23e28e6..068dd965dd 100644 --- a/packages/frontend/scss/login/_login.scss +++ b/packages/frontend/scss/login/_login.scss @@ -152,6 +152,23 @@ div.delta-form-group { } } + &.delta-switch { + > label { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + width: 100%; + height: auto; + font-size: 15px; + line-height: normal; + cursor: pointer; + color: var(--deltaChatPrimaryFgLight); + padding-inline-end: 5px; + padding-block-end: 4px; + } + } + &.delta-input { input { appearance: none; diff --git a/packages/frontend/src/components/LoginForm.tsx b/packages/frontend/src/components/LoginForm.tsx index 4419bd5717..d2eefde7b3 100644 --- a/packages/frontend/src/components/LoginForm.tsx +++ b/packages/frontend/src/components/LoginForm.tsx @@ -12,6 +12,8 @@ import { I18nContext } from '../contexts/I18nContext' const log = getLogger('renderer/loginForm') import type { Credentials } from './Settings/DefaultCredentials' +import { useSettingsStore } from '../stores/settings' +import Switch from './Switch' const Socket = { automatic: 'automatic', @@ -29,6 +31,8 @@ const CertificateChecks = { type LoginProps = React.PropsWithChildren<{ credentials: Credentials setCredentials: (credentials: Credentials) => void + forceEncryption?: boolean + setForceEncryption?: (forceEncryption: boolean) => void /** whether editing existing account */ isEdit?: true }> @@ -36,12 +40,17 @@ type LoginProps = React.PropsWithChildren<{ export default function LoginForm({ credentials, setCredentials, + forceEncryption: forceEncryptionProp, + setForceEncryption, isEdit, }: LoginProps) { const [uiShowAdvanced, setUiShowAdvanced] = useState(false) const [providerInfo, setProviderInfo] = useState< Type.ProviderInfo | undefined >() + const settingsStore = useSettingsStore()[0] + const forceEncryption = + forceEncryptionProp ?? settingsStore?.settings['force_encryption'] === '1' const handleCredentialsChange = ( event: React.ChangeEvent @@ -260,7 +269,6 @@ export default function LoginForm({ - +
+ +

diff --git a/packages/frontend/src/components/dialogs/EditAccountAndPasswordDialog.tsx b/packages/frontend/src/components/dialogs/EditAccountAndPasswordDialog.tsx index 1891e18c05..eff0618965 100644 --- a/packages/frontend/src/components/dialogs/EditAccountAndPasswordDialog.tsx +++ b/packages/frontend/src/components/dialogs/EditAccountAndPasswordDialog.tsx @@ -16,7 +16,7 @@ import useDialog from '../../hooks/dialog/useDialog' import type { DialogProps } from '../../contexts/DialogContext' import AlertDialog from './AlertDialog' import { T } from '@deltachat/jsonrpc-client' -import { useSettingsStore } from '../../stores/settings' +import SettingsStoreInstance, { useSettingsStore } from '../../stores/settings' import { getLogger } from '@deltachat-desktop/shared/logger' type AccountAndPasswordDialogProps = DialogProps & { @@ -57,11 +57,15 @@ function EditAccountInner({ onClose: DialogProps['onClose'] addr?: string }) { + const settingsStore = useSettingsStore()[0] const [initialSettings, setInitialAccountSettings] = useState(defaultCredentials()) const [accountSettings, setAccountSettings] = useState(defaultCredentials()) + const [forceEncryption, setForceEncryption] = useState( + settingsStore?.settings['force_encryption'] === '1' + ) const { openDialog } = useDialog() const tx = useTranslationFunction() @@ -105,7 +109,18 @@ function EditAccountInner({ }, [addr]) const onUpdate = useCallback(async () => { - const onSuccess = () => onClose() + const onSuccess = async () => { + const forceEncryptionValue = forceEncryption ? '1' : '0' + if ( + settingsStore?.settings['force_encryption'] !== forceEncryptionValue + ) { + await SettingsStoreInstance.effect.setCoreSetting( + 'force_encryption', + forceEncryptionValue + ) + } + onClose() + } const update = () => { openDialog(ConfigureProgressDialog, { @@ -121,8 +136,16 @@ function EditAccountInner({ log.error('changing email addres of transport is not allowed') return } + update() - }, [accountSettings, initialSettings, onClose, openDialog]) + }, [ + accountSettings, + forceEncryption, + initialSettings, + onClose, + openDialog, + settingsStore, + ]) const onOk = useCallback(async () => { await onUpdate() @@ -137,6 +160,8 @@ function EditAccountInner({ )} diff --git a/packages/frontend/src/components/screens/AccountSetupScreen.tsx b/packages/frontend/src/components/screens/AccountSetupScreen.tsx index 00344605c5..5ce5fafa3f 100644 --- a/packages/frontend/src/components/screens/AccountSetupScreen.tsx +++ b/packages/frontend/src/components/screens/AccountSetupScreen.tsx @@ -16,6 +16,7 @@ import useTranslationFunction from '../../hooks/useTranslationFunction' import useDialog from '../../hooks/dialog/useDialog' import { DialogId } from '../../contexts/DialogContext' import AlertDialog from '../dialogs/AlertDialog' +import SettingsStoreInstance, { useSettingsStore } from '../../stores/settings' import type ScreenController from '../../ScreenController' @@ -32,25 +33,43 @@ export default function AccountSetupScreen({ const [credentials, setCredentials] = useState(defaultCredentials()) - - const onClickLogin = useCallback( - () => - openDialog(ConfigureProgressDialog, { - credentials, - onSuccess: () => { - selectAccount(accountId) - }, - onFail: (error: string) => - setPromptDialogId( - openDialog(AlertDialog, { - message: error, - cb: () => setPromptDialogId(null), - }) - ), - }), - [accountId, openDialog, selectAccount, credentials] + const settingsStore = useSettingsStore()[0] + const [forceEncryption, setForceEncryption] = useState( + settingsStore?.settings['force_encryption'] === '1' ) + const onClickLogin = useCallback(() => { + openDialog(ConfigureProgressDialog, { + credentials, + onSuccess: async () => { + const forceEncryptionValue = forceEncryption ? '1' : '0' + if ( + settingsStore?.settings['force_encryption'] !== forceEncryptionValue + ) { + await SettingsStoreInstance.effect.setCoreSetting( + 'force_encryption', + forceEncryptionValue + ) + } + selectAccount(accountId) + }, + onFail: (error: string) => + setPromptDialogId( + openDialog(AlertDialog, { + message: error, + cb: () => setPromptDialogId(null), + }) + ), + }) + }, [ + accountId, + credentials, + forceEncryption, + openDialog, + selectAccount, + settingsStore, + ]) + // TODO(maxph): we're now using and can submit result via input // and not an explicit keyboard handling const onKeyDown = useCallback( @@ -88,6 +107,8 @@ export default function AccountSetupScreen({ diff --git a/packages/frontend/src/stores/settings.ts b/packages/frontend/src/stores/settings.ts index 4bf255aab5..69a7239cba 100644 --- a/packages/frontend/src/stores/settings.ts +++ b/packages/frontend/src/stores/settings.ts @@ -18,6 +18,7 @@ export interface SettingsStoreState { bcc_self: string delete_device_after: string download_limit: string + force_encryption: '0' | '1' media_quality: string is_chatmail: '0' | '1' who_can_call_me: WhoCanCallMe @@ -36,6 +37,7 @@ const settingsKeys = [ 'bcc_self', 'delete_device_after', 'download_limit', + 'force_encryption', 'media_quality', 'is_chatmail', 'who_can_call_me',