import { systemPreferences } from '@electron/remote'; import { mdiGithub, mdiOpenInNew, mdiPowerPlug } from '@mdi/js'; import { noop } from 'lodash'; import { observer } from 'mobx-react'; import prettyBytes from 'pretty-bytes'; import { Component, type ReactElement } from 'react'; import { type WrappedComponentProps, defineMessages, injectIntl, } from 'react-intl'; import { DEFAULT_ACCENT_COLOR, DEFAULT_APP_SETTINGS, FERDIUM_TRANSLATION, GITHUB_FERDIUM_URL, GITHUB_FRANZ_URL, SPLIT_COLUMNS_MAX, SPLIT_COLUMNS_MIN, } from '../../../config'; import { isMac, isWinPortable, isWindows, lockFerdiumShortcutKey, } from '../../../environment'; import { ferdiumVersion, userDataCertsPath, userDataPath, userDataRecipesPath, } from '../../../environment-remote'; import { updateVersionParse } from '../../../helpers/update-helpers'; import { openExternalUrl, openPath } from '../../../helpers/url-helpers'; import globalMessages from '../../../i18n/globalMessages'; import type Form from '../../../lib/Form'; import Infobox from '../../ui/Infobox'; import Select from '../../ui/Select'; import Slider from '../../ui/Slider'; import Button from '../../ui/button'; import ColorPickerInput from '../../ui/colorPickerInput'; import { H1, H2, H3, H5 } from '../../ui/headline'; import Icon from '../../ui/icon'; import Input from '../../ui/input/index'; import Toggle from '../../ui/toggle'; const debug = require('../../../preload-safe-debug')( 'Ferdium:EditSettingsForm', ); const messages = defineMessages({ headlineGeneral: { id: 'settings.app.headlineGeneral', defaultMessage: 'General', }, headlineServices: { id: 'settings.app.headlineServices', defaultMessage: 'Services', }, sentryInfo: { id: 'settings.app.sentryInfo', defaultMessage: 'Sending telemetry data allows us to find errors in Ferdium - we will not send any personal information like your message data!', }, hibernateInfo: { id: 'settings.app.hibernateInfo', defaultMessage: 'By default, Ferdium will keep all your services open and loaded in the background so they are ready when you want to use them. Service Hibernation will unload your services after a specified amount. This is useful to save RAM or keeping services from slowing down your computer.', }, inactivityLockInfo: { id: 'settings.app.inactivityLockInfo', defaultMessage: 'Minutes of inactivity, after which Ferdium should automatically lock. Use 0 to disable', }, todoServerInfo: { id: 'settings.app.todoServerInfo', defaultMessage: 'This server will be used for the "Ferdium Todo" feature.', }, lockedPassword: { id: 'settings.app.lockedPassword', defaultMessage: 'Password', }, lockedPasswordInfo: { id: 'settings.app.lockedPasswordInfo', defaultMessage: "Please make sure to set a password you'll remember.\nIf you loose this password, you will have to reinstall Ferdium.", }, lockInfo: { id: 'settings.app.lockInfo', defaultMessage: 'Password Lock allows you to keep your messages protected.\nUsing Password Lock, you will be prompted to enter your password everytime you start Ferdium or lock Ferdium yourself using the lock symbol in the bottom left corner or the shortcut {lockShortcut}.', }, scheduledDNDTimeInfo: { id: 'settings.app.scheduledDNDTimeInfo', defaultMessage: 'Times in 24-Hour-Format. End time can be before start time (e.g. start 17:00, end 09:00) to enable Do-not-Disturb overnight.', }, scheduledDNDInfo: { id: 'settings.app.scheduledDNDInfo', defaultMessage: 'Scheduled Do-not-Disturb allows you to define a period of time in which you do not want to get Notifications from Ferdium.', }, headlineLanguage: { id: 'settings.app.headlineLanguage', defaultMessage: 'Language', }, headlineUpdates: { id: 'settings.app.headlineUpdates', defaultMessage: 'Updates', }, headlineAppearance: { id: 'settings.app.headlineAppearance', defaultMessage: 'Appearance', }, sectionMain: { id: 'settings.app.sectionMain', defaultMessage: 'Main', }, sectionHibernation: { id: 'settings.app.sectionHibernation', defaultMessage: 'Hibernation', }, sectionGeneralUi: { id: 'settings.app.sectionGeneralUi', defaultMessage: 'General UI', }, sectionSidebarSettings: { id: 'settings.app.sectionSidebarSettings', defaultMessage: 'Sidebar Settings', }, sectionPrivacy: { id: 'settings.app.sectionPrivacy', defaultMessage: 'Privacy Settings', }, sectionLanguage: { id: 'settings.app.sectionLanguage', defaultMessage: 'Language Settings', }, sectionAdvanced: { id: 'settings.app.sectionAdvanced', defaultMessage: 'Advanced Settings', }, sectionUpdates: { id: 'settings.app.sectionUpdates', defaultMessage: 'App Updates Settings', }, sectionServiceIconsSettings: { id: 'settings.app.sectionServiceIconsSettings', defaultMessage: 'Service Icons Settings', }, sectionAccentColorSettings: { id: 'settings.app.sectionAccentColorSettings', defaultMessage: 'Accent Color Settings', }, accentColorInfo: { id: 'settings.app.accentColorInfo', defaultMessage: 'Write your color choice in a CSS-compatible format. (Default: {defaultAccentColor} or clear the input field)', }, overallTheme: { id: 'settings.app.overallTheme', defaultMessage: 'Overall Theme', }, progressbarTheme: { id: 'settings.app.progressbarTheme', defaultMessage: 'Progressbar Theme', }, universalDarkModeInfo: { id: 'settings.app.universalDarkModeInfo', defaultMessage: 'Universal Dark Mode tries to dynamically generate dark mode styles for services that are otherwise not currently supported.', }, headlinePrivacy: { id: 'settings.app.headlinePrivacy', defaultMessage: 'Privacy', }, headlineAdvanced: { id: 'settings.app.headlineAdvanced', defaultMessage: 'Advanced', }, translationHelp: { id: 'settings.app.translationHelp', defaultMessage: 'Help us to translate Ferdium into your language.', }, spellCheckerLanguageInfo: { id: 'settings.app.spellCheckerLanguageInfo', defaultMessage: "Ferdium uses your Mac's build-in spellchecker to check for typos. If you want to change the languages the spellchecker checks for, you can do so in your Mac's System Preferences.", }, subheadlineCache: { id: 'settings.app.subheadlineCache', defaultMessage: 'Cache', }, cacheInfo: { id: 'settings.app.cacheInfo', defaultMessage: 'Ferdium cache is currently using {size} of disk space.', }, cacheNotCleared: { id: 'settings.app.cacheNotCleared', defaultMessage: "Couldn't clear all cache", }, subheadlineFerdiumProfile: { id: 'settings.app.subheadlineFerdiumProfile', defaultMessage: 'Ferdium Profile', }, buttonOpenFerdiumProfileFolder: { id: 'settings.app.buttonOpenFerdiumProfileFolder', defaultMessage: 'Open Profile folder', }, buttonOpenFerdiumServiceRecipesFolder: { id: 'settings.app.buttonOpenFerdiumServiceRecipesFolder', defaultMessage: 'Open Service Recipes folder', }, buttonOpenImportExport: { id: 'settings.app.buttonOpenImportExport', defaultMessage: 'Import / Export', }, serverHelp: { id: 'settings.app.serverHelp', defaultMessage: 'Connected to server at {serverURL}', }, buttonSearchForUpdate: { id: 'settings.app.buttonSearchForUpdate', defaultMessage: 'Check for updates', }, buttonInstallUpdate: { id: 'settings.app.buttonInstallUpdate', defaultMessage: 'Restart & install update', }, buttonShowChangelog: { id: 'settings.app.buttonShowChangelog', defaultMessage: 'Show changelog', }, updateStatusSearching: { id: 'settings.app.updateStatusSearching', defaultMessage: 'Searching for updates...', }, updateStatusAvailable: { id: 'settings.app.updateStatusAvailable', defaultMessage: 'Update available, downloading...', }, updateStatusUpToDate: { id: 'settings.app.updateStatusUpToDate', defaultMessage: 'You are using the latest version of Ferdium', }, servicesUpdateStatusUpToDate: { id: 'settings.app.servicesUpdateStatusUpToDate', defaultMessage: 'Your services are up-to-date', }, currentVersion: { id: 'settings.app.currentVersion', defaultMessage: 'Current version:', }, appRestartRequired: { id: 'settings.app.restartRequired', defaultMessage: 'Changes require restart', }, servicesUpdated: { id: 'infobar.servicesUpdated', defaultMessage: 'Your services have been updated.', }, buttonReloadServices: { id: 'infobar.buttonReloadServices', defaultMessage: 'Reload services', }, numberOfColumns: { id: 'settings.app.form.splitColumns', defaultMessage: 'Number of columns', }, warningSelfSignedCertificates: { id: 'settings.app.warningSelfSignedCertificates', defaultMessage: 'WARNING: Only enable this feature if you know what you are doing. Enabling this is a security risk and should only be used for testing purposes.', }, infoOpenCertificatesFolder: { id: 'settings.app.infoOpenCertificatesFolder', defaultMessage: 'To install a certificate, click the button below to open the certificates folder and copy it into the folder. After that you can refresh the service (CTRL/CMD + R). To remove/uninstall, simply delete the certificate file and restart Ferdium.', }, buttonOpenFerdiumCertsFolder: { id: 'settings.app.buttonOpenFerdiumCertsFolder', defaultMessage: 'Open certificates folder', }, }); const Hr = (): ReactElement => (
); const HrSections = (): ReactElement => (
); interface IProps extends WrappedComponentProps { form: Form; isCheckingForUpdates: boolean; isUpdateAvailable: boolean; noUpdateAvailable: boolean; updateIsReadyToInstall: boolean; updateFailed: boolean; isClearingAllCache: boolean; isTodosActivated: boolean; automaticUpdates: boolean; isTwoFactorAutoCatcherEnabled: boolean; twoFactorAutoCatcherMatcher: string; isDarkmodeEnabled: boolean; isAdaptableDarkModeEnabled: boolean; isUseGrayscaleServicesEnabled: boolean; isLockingFeatureEnabled: boolean; isSplitModeEnabled: boolean; isOnline: boolean; showServicesUpdatedInfoBar: boolean; updateVersion: string; serverURL: string; onClearAllCache: () => void; getCacheSize: () => void; checkForUpdates: () => void; installUpdate: () => void; openProcessManager: () => void; onSubmit: (...args: any[]) => void; } interface IState { activeSetttingsTab: string; clearCacheButtonClicked: boolean; } @observer class EditSettingsForm extends Component { constructor(props: IProps) { super(props); this.state = { activeSetttingsTab: 'general', clearCacheButtonClicked: false, }; } setActiveSettingsTab(tab) { this.setState({ activeSetttingsTab: tab, }); } onClearCacheClicked = () => { this.setState({ clearCacheButtonClicked: true }); }; submit(e): void { if (e) { e.preventDefault(); } this.props.form.submit({ onSuccess: (form: Form) => { const values = form.values(); const { accentColor, isTwoFactorAutoCatcherEnabled } = values; if (accentColor.trim().length === 0) { values.accentColor = DEFAULT_ACCENT_COLOR; } const { progressbarAccentColor } = values; if (progressbarAccentColor.trim().length === 0) { values.progressbarAccentColor = DEFAULT_ACCENT_COLOR; } // set twoFactorAutoCatcherMatcher to the default value, if its get enabled the input is prefilled if ( !isTwoFactorAutoCatcherEnabled && values.twoFactorAutoCatcherMatcher.length === 0 ) { values.twoFactorAutoCatcherMatcher = DEFAULT_APP_SETTINGS.twoFactorAutoCatcherMatcher; } this.props.onSubmit(values); }, onError: noop, }); } render(): ReactElement { const { checkForUpdates, installUpdate, form, updateVersion, isCheckingForUpdates, isAdaptableDarkModeEnabled, isUseGrayscaleServicesEnabled, isUpdateAvailable, noUpdateAvailable, updateIsReadyToInstall, updateFailed, showServicesUpdatedInfoBar, isClearingAllCache, onClearAllCache, getCacheSize, automaticUpdates, isTwoFactorAutoCatcherEnabled, isDarkmodeEnabled, isSplitModeEnabled, openProcessManager, isTodosActivated, isOnline, serverURL, intl, } = this.props; let updateButtonLabelMessage = messages.buttonSearchForUpdate; if (isCheckingForUpdates) { updateButtonLabelMessage = messages.updateStatusSearching; } else if (isUpdateAvailable) { updateButtonLabelMessage = messages.updateStatusAvailable; } const { isLockingFeatureEnabled, scheduledDNDEnabled, reloadAfterResume, useSelfSignedCertificates, } = window['ferdium'].stores.settings.all.app; let cacheSize; let notCleared; if (this.state.activeSetttingsTab === 'advanced') { const cacheSizeBytes = getCacheSize(); debug('cacheSizeBytes:', cacheSizeBytes); if (typeof cacheSizeBytes === 'number') { cacheSize = prettyBytes(cacheSizeBytes); debug('cacheSize:', cacheSize); notCleared = this.state.clearCacheButtonClicked && !isClearingAllCache && cacheSizeBytes !== 0; } else { cacheSize = '…'; notCleared = false; } } const profileFolder = userDataPath(); const recipeFolder = userDataRecipesPath(); const certsFolder = userDataCertsPath(); return (

{intl.formatMessage(globalMessages.settings)}

this.submit(e)} onChange={e => this.submit(e)} id="form" > {/* Titles */}
{ this.setActiveSettingsTab('general'); }} > {intl.formatMessage(messages.headlineGeneral)}
{ this.setActiveSettingsTab('services'); }} > {intl.formatMessage(messages.headlineServices)}
{ this.setActiveSettingsTab('appearance'); }} > {intl.formatMessage(messages.headlineAppearance)}
{ this.setActiveSettingsTab('privacy'); }} > {intl.formatMessage(messages.headlinePrivacy)}
{ this.setActiveSettingsTab('language'); }} > {intl.formatMessage(messages.headlineLanguage)}
{ this.setActiveSettingsTab('advanced'); }} > {intl.formatMessage(messages.headlineAdvanced)}
{ this.setActiveSettingsTab('updates'); }} > {intl.formatMessage(messages.headlineUpdates)} {automaticUpdates && (updateIsReadyToInstall || isUpdateAvailable || showServicesUpdatedInfoBar) && ( )}
{/* General */} {this.state.activeSetttingsTab === 'general' && (

{intl.formatMessage(messages.sectionMain)}

{reloadAfterResume &&
} {reloadAfterResume && (

)} {isWindows && ( )} {isWindows && ( )} {isTodosActivated &&
} {isTodosActivated && (
this.submit(e)} {...form.$('customTodoServer').bind()} />

{intl.formatMessage(messages.todoServerInfo)}

)}
)} {isTodosActivated &&
} {scheduledDNDEnabled &&
} {scheduledDNDEnabled && ( <>
this.submit(e)} {...form.$('scheduledDNDStart').bind()} type="time" />
this.submit(e)} {...form.$('scheduledDNDEnd').bind()} type="time" />

{intl.formatMessage(messages.scheduledDNDTimeInfo)}

)}

{intl.formatMessage(messages.scheduledDNDInfo)}

)} {/* Services */} {this.state.activeSetttingsTab === 'services' && (

{intl.formatMessage(messages.sectionServiceIconsSettings)}

{isUseGrayscaleServicesEnabled &&
} {isUseGrayscaleServicesEnabled && ( <> this.submit(e)} field={form.$('grayscaleServicesDim')} />
)}

{intl.formatMessage(messages.sectionHibernation)}

this.submit(e)} {...form.$('splitColumns').bind()} /> )}

{intl.formatMessage(messages.sectionAccentColorSettings)}

{intl.formatMessage(messages.accentColorInfo, { defaultAccentColor: DEFAULT_APP_SETTINGS.accentColor, })}

{intl.formatMessage(messages.overallTheme)}

this.submit(e)} className="color-picker-input" />

{intl.formatMessage(messages.progressbarTheme)}

this.submit(e)} className="color-picker-input" />

{intl.formatMessage(messages.sectionSidebarSettings)}

)} {/* Privacy */} {this.state.activeSetttingsTab === 'privacy' && (

{intl.formatMessage(messages.sectionPrivacy)}

{(isWindows || isMac) && ( )} {isTwoFactorAutoCatcherEnabled && ( this.submit(e)} {...form.$('twoFactorAutoCatcherMatcher').bind()} /> )}

{intl.formatMessage(messages.appRestartRequired)}


{isLockingFeatureEnabled && ( <> {isMac && systemPreferences.canPromptTouchID() && ( )} this.submit(e)} {...form.$('lockedPassword')} type="password" scorePassword showPasswordToggle />

{intl.formatMessage(messages.lockedPasswordInfo)}

this.submit(e)} {...form.$('inactivityLock')} autoFocus />

{intl.formatMessage(messages.inactivityLockInfo)}

)}

{intl.formatMessage(messages.lockInfo, { lockShortcut: `${lockFerdiumShortcutKey(false)}`, })}

)} {/* Language */} {this.state.activeSetttingsTab === 'language' && (

{intl.formatMessage(messages.sectionLanguage)}

)} {isMac && form.$('enableSpellchecking').value && (

{intl.formatMessage(messages.spellCheckerLanguageInfo)}

)}

{intl.formatMessage(messages.appRestartRequired)}


{form.$('enableTranslator').value && ( )}
{intl.formatMessage(messages.translationHelp)}{' '}
)} {/* Advanced */} {this.state.activeSetttingsTab === 'advanced' && (

{intl.formatMessage(messages.sectionAdvanced)}

{intl.formatMessage(messages.appRestartRequired)}

{useSelfSignedCertificates && (

{intl.formatMessage(messages.infoOpenCertificatesFolder)}

)}

{intl.formatMessage(messages.warningSelfSignedCertificates)}


this.submit(e)} {...form.$('userAgentPref').bind()} />

{intl.formatMessage(globalMessages.userAgentHelp)}

{intl.formatMessage(messages.appRestartRequired)}


{intl.formatMessage(messages.subheadlineCache)}

{intl.formatMessage(messages.cacheInfo, { size: cacheSize, })}

{notCleared && (

{intl.formatMessage(messages.cacheNotCleared)}

)}

{intl.formatMessage(messages.subheadlineFerdiumProfile)}

{intl.formatMessage(messages.serverHelp, { serverURL, })}

)} {/* Updates */} {this.state.activeSetttingsTab === 'updates' && (

{intl.formatMessage(messages.sectionUpdates)}

{automaticUpdates && !isWinPortable && ( <> <>
{updateIsReadyToInstall ? (

{intl.formatMessage(messages.currentVersion)}{' '} {ferdiumVersion}

{noUpdateAvailable && (

{intl.formatMessage(messages.updateStatusUpToDate)}.

)} {updateFailed && (  An error occurred (check the console for more details) )} {showServicesUpdatedInfoBar ? ( <>

{intl.formatMessage(messages.servicesUpdated)}

)}
); } } export default injectIntl(EditSettingsForm);