Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _locales/_untranslated_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
19 changes: 19 additions & 0 deletions packages/frontend/scss/login/_login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ div.delta-form-group {
}
}

&.delta-switch {
overflow: visible;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
overflow: visible;

This doesn't do anything, right? It's the default value anyway.

> 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;
Expand Down
30 changes: 29 additions & 1 deletion packages/frontend/src/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { I18nContext } from '../contexts/I18nContext'
const log = getLogger('renderer/loginForm')

import type { Credentials } from './Settings/DefaultCredentials'
import SettingsStoreInstance, { useSettingsStore } from '../stores/settings'
import Switch from './Switch'

const Socket = {
automatic: 'automatic',
Expand All @@ -29,19 +31,26 @@ const CertificateChecks = {
type LoginProps = React.PropsWithChildren<{
credentials: Credentials
setCredentials: (credentials: Credentials) => void
forceEncryption?: boolean
setForceEncryption?: (forceEncryption: boolean) => void
/** whether editing existing account */
isEdit?: true
}>

export default function LoginForm({
credentials,
setCredentials,
forceEncryption: forceEncryptionProp,
setForceEncryption,
isEdit,
}: LoginProps) {
const [uiShowAdvanced, setUiShowAdvanced] = useState<boolean>(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<HTMLInputElement>
Expand Down Expand Up @@ -260,7 +269,6 @@ export default function LoginForm({
<option value={Socket.starttls}>STARTTLS</option>
<option value={Socket.plain}>{tx('off')}</option>
</DeltaSelect>

<DeltaSelect
id='certificateChecks'
label={tx('login_certificate_checks')}
Expand All @@ -275,6 +283,26 @@ export default function LoginForm({
{tx('accept_invalid_certificates')}
</option>
</DeltaSelect>
<div className='delta-form-group delta-switch'>
<label>
<span>{tx('enforce_e2ee')}</span>
{/** be aware that this setting applies to all relays! */}
<Switch
checked={forceEncryption}
disabled={settingsStore == null}
onChange={() => {
if (setForceEncryption) {
setForceEncryption(!forceEncryption)
return
}
SettingsStoreInstance.effect.setCoreSetting(
'force_encryption',
forceEncryption ? '0' : '1'
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically unused now, right?

}}
/>
</label>
</div>
</Collapse>
<br />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -57,11 +57,15 @@ function EditAccountInner({
onClose: DialogProps['onClose']
addr?: string
}) {
const settingsStore = useSettingsStore()[0]
const [initialSettings, setInitialAccountSettings] =
useState<Credentials>(defaultCredentials())

const [accountSettings, setAccountSettings] =
useState<Credentials>(defaultCredentials())
const [forceEncryption, setForceEncryption] = useState<boolean>(
settingsStore?.settings['force_encryption'] !== '0'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settingsStore?.settings['force_encryption'] !== '0'
settingsStore?.settings['force_encryption'] === '1'

We already changed this in one place, so let's be consistent? Especially here where the settingsStore can be nullish. See #6410 (comment)

)

const { openDialog } = useDialog()
const tx = useTranslationFunction()
Expand Down Expand Up @@ -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, {
Expand All @@ -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()
Expand All @@ -137,6 +160,8 @@ function EditAccountInner({
<LoginForm
credentials={accountSettings}
setCredentials={setAccountSettings}
forceEncryption={forceEncryption}
setForceEncryption={setForceEncryption}
isEdit
/>
)}
Expand Down
55 changes: 38 additions & 17 deletions packages/frontend/src/components/screens/AccountSetupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -32,25 +33,43 @@ export default function AccountSetupScreen({

const [credentials, setCredentials] =
useState<Credentials>(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<boolean>(
settingsStore?.settings['force_encryption'] !== '0'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settingsStore?.settings['force_encryption'] !== '0'
settingsStore?.settings['force_encryption'] === '1'

See #6410 (comment)

)

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 <dialog> and can submit result via input
// and not an explicit keyboard handling
const onKeyDown = useCallback(
Expand Down Expand Up @@ -88,6 +107,8 @@ export default function AccountSetupScreen({
<LoginForm
credentials={credentials}
setCredentials={setCredentials}
forceEncryption={forceEncryption}
setForceEncryption={setForceEncryption}
/>
</DialogContent>
</DialogBody>
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@ const settingsKeys = [
'bcc_self',
'delete_device_after',
'download_limit',
'force_encryption',
'media_quality',
'is_chatmail',
'who_can_call_me',
Expand Down
Loading