2020-09-15 15:01:07 +02:00
|
|
|
import * as React from 'react';
|
2021-01-12 14:28:55 +02:00
|
|
|
import Sidebar from './Sidebar';
|
2020-09-15 15:01:07 +02:00
|
|
|
import ButtonBar from './ButtonBar';
|
2021-10-03 17:00:49 +02:00
|
|
|
import Button, { ButtonLevel, ButtonSize } from '../Button/Button';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-11-19 14:34:49 +02:00
|
|
|
import bridge from '../../services/bridge';
|
2021-06-19 18:32:36 +02:00
|
|
|
import Setting, { AppType, SyncStartupOperation } from '@joplin/lib/models/Setting';
|
2021-01-07 18:30:53 +02:00
|
|
|
import control_PluginsStates from './controls/plugins/PluginsStates';
|
2021-09-10 20:05:47 +02:00
|
|
|
import EncryptionConfigScreen from '../EncryptionConfigScreen/EncryptionConfigScreen';
|
2022-04-13 13:38:09 +02:00
|
|
|
import { reg } from '@joplin/lib/registry';
|
2017-11-12 02:44:26 +02:00
|
|
|
const { connect } = require('react-redux');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { themeStyle } = require('@joplin/lib/theme');
|
2024-01-18 13:20:10 +02:00
|
|
|
import * as pathUtils from '@joplin/lib/path-utils';
|
2021-08-16 16:20:14 +02:00
|
|
|
import SyncTargetRegistry from '@joplin/lib/SyncTargetRegistry';
|
2023-11-09 21:19:08 +02:00
|
|
|
import * as shared from '@joplin/lib/components/shared/config/config-shared.js';
|
2021-08-07 13:22:37 +02:00
|
|
|
import ClipperConfigScreen from '../ClipperConfigScreen';
|
2022-04-20 18:34:58 +02:00
|
|
|
import restart from '../../services/restart';
|
2023-07-18 21:15:45 +02:00
|
|
|
import JoplinCloudConfigScreen from '../JoplinCloudConfigScreen';
|
2023-08-08 16:50:51 +02:00
|
|
|
import ToggleAdvancedSettingsButton from './controls/ToggleAdvancedSettingsButton';
|
2023-08-14 19:12:49 +02:00
|
|
|
import shouldShowMissingPasswordWarning from '@joplin/lib/components/shared/config/shouldShowMissingPasswordWarning';
|
2023-08-19 10:17:25 +02:00
|
|
|
import MacOSMissingPasswordHelpLink from './controls/MissingPasswordHelpLink';
|
2020-09-15 15:01:07 +02:00
|
|
|
const { KeymapConfigScreen } = require('../KeymapConfig/KeymapConfigScreen');
|
2018-02-06 20:59:36 +02:00
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
const settingKeyToControl: any = {
|
|
|
|
'plugins.states': control_PluginsStates,
|
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
class ConfigScreenComponent extends React.Component<any, any> {
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
private rowStyle_: any = null;
|
2018-02-06 20:59:36 +02:00
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public constructor(props: any) {
|
2020-09-15 15:01:07 +02:00
|
|
|
super(props);
|
2019-12-13 03:16:34 +02:00
|
|
|
|
2023-11-09 21:19:08 +02:00
|
|
|
shared.init(reg);
|
2019-12-13 03:16:34 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
this.state = {
|
2023-11-09 21:19:08 +02:00
|
|
|
...shared.defaultScreenState,
|
2020-09-15 15:01:07 +02:00
|
|
|
selectedSectionName: 'general',
|
|
|
|
screenName: '',
|
|
|
|
changedSettingKeys: [],
|
2020-11-19 14:34:49 +02:00
|
|
|
needRestart: false,
|
2019-12-13 03:16:34 +02:00
|
|
|
};
|
|
|
|
|
2018-02-06 20:59:36 +02:00
|
|
|
this.rowStyle_ = {
|
|
|
|
marginBottom: 10,
|
|
|
|
};
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2021-01-12 14:28:55 +02:00
|
|
|
this.sidebar_selectionChange = this.sidebar_selectionChange.bind(this);
|
2020-09-15 15:01:07 +02:00
|
|
|
this.checkSyncConfig_ = this.checkSyncConfig_.bind(this);
|
|
|
|
this.onCancelClick = this.onCancelClick.bind(this);
|
|
|
|
this.onSaveClick = this.onSaveClick.bind(this);
|
|
|
|
this.onApplyClick = this.onApplyClick.bind(this);
|
2020-11-19 14:34:49 +02:00
|
|
|
this.renderLabel = this.renderLabel.bind(this);
|
|
|
|
this.renderDescription = this.renderDescription.bind(this);
|
2021-01-09 15:14:39 +02:00
|
|
|
this.renderHeader = this.renderHeader.bind(this);
|
2021-05-03 12:55:38 +02:00
|
|
|
this.handleSettingButton = this.handleSettingButton.bind(this);
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
private async checkSyncConfig_() {
|
2020-09-15 15:01:07 +02:00
|
|
|
await shared.checkSyncConfig(this, this.state.settings);
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public UNSAFE_componentWillMount() {
|
2017-12-08 00:29:02 +02:00
|
|
|
this.setState({ settings: this.props.settings });
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public componentDidMount() {
|
2019-09-11 01:53:01 +02:00
|
|
|
if (this.props.defaultSection) {
|
|
|
|
this.setState({ selectedSectionName: this.props.defaultSection }, () => {
|
2024-01-27 20:20:51 +02:00
|
|
|
void this.switchSection(this.props.defaultSection);
|
2019-09-11 01:53:01 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 12:55:38 +02:00
|
|
|
private async handleSettingButton(key: string) {
|
|
|
|
if (key === 'sync.clearLocalSyncStateButton') {
|
|
|
|
if (!confirm('This cannot be undone. Do you want to continue?')) return;
|
|
|
|
Setting.setValue('sync.startupOperation', SyncStartupOperation.ClearLocalSyncState);
|
|
|
|
await Setting.saveAll();
|
2022-04-20 18:34:58 +02:00
|
|
|
await restart();
|
2021-05-03 12:55:38 +02:00
|
|
|
} else if (key === 'sync.clearLocalDataButton') {
|
|
|
|
if (!confirm('This cannot be undone. Do you want to continue?')) return;
|
|
|
|
Setting.setValue('sync.startupOperation', SyncStartupOperation.ClearLocalData);
|
|
|
|
await Setting.saveAll();
|
2022-04-20 18:34:58 +02:00
|
|
|
await restart();
|
2021-08-16 16:20:14 +02:00
|
|
|
} else if (key === 'sync.openSyncWizard') {
|
|
|
|
this.props.dispatch({
|
|
|
|
type: 'DIALOG_OPEN',
|
|
|
|
name: 'syncWizard',
|
|
|
|
});
|
2021-05-03 12:55:38 +02:00
|
|
|
} else {
|
|
|
|
throw new Error(`Unhandled key: ${key}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public sectionByName(name: string) {
|
2023-11-09 21:19:08 +02:00
|
|
|
const sections = shared.settingsSections({ device: AppType.Desktop, settings: this.state.settings });
|
2019-09-11 01:53:01 +02:00
|
|
|
for (const section of sections) {
|
|
|
|
if (section.name === name) return section;
|
|
|
|
}
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`Invalid section name: ${name}`);
|
2019-09-11 01:53:01 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public screenFromName(screenName: string) {
|
2021-12-20 17:08:43 +02:00
|
|
|
if (screenName === 'encryption') return <EncryptionConfigScreen/>;
|
2020-09-15 15:01:07 +02:00
|
|
|
if (screenName === 'server') return <ClipperConfigScreen themeId={this.props.themeId}/>;
|
|
|
|
if (screenName === 'keymap') return <KeymapConfigScreen themeId={this.props.themeId}/>;
|
2023-07-18 21:15:45 +02:00
|
|
|
if (screenName === 'joplinCloud') return <JoplinCloudConfigScreen />;
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
throw new Error(`Invalid screen name: ${screenName}`);
|
2019-09-11 01:53:01 +02:00
|
|
|
}
|
|
|
|
|
2024-01-27 20:20:51 +02:00
|
|
|
public async switchSection(name: string) {
|
2019-09-11 01:53:01 +02:00
|
|
|
const section = this.sectionByName(name);
|
|
|
|
let screenName = '';
|
|
|
|
if (section.isScreen) {
|
|
|
|
screenName = section.name;
|
|
|
|
|
|
|
|
if (this.hasChanges()) {
|
|
|
|
const ok = confirm(_('This will open a new screen. Save your current changes?'));
|
2024-01-27 20:20:51 +02:00
|
|
|
if (ok) {
|
|
|
|
await shared.saveSettings(this);
|
|
|
|
}
|
2019-09-11 01:53:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ selectedSectionName: section.name, screenName: screenName });
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
private sidebar_selectionChange(event: any) {
|
2024-01-27 20:20:51 +02:00
|
|
|
void this.switchSection(event.section.name);
|
2019-09-11 01:53:01 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public renderSectionDescription(section: any) {
|
2020-04-10 19:33:09 +02:00
|
|
|
const description = Setting.sectionDescription(section.name);
|
|
|
|
if (!description) return null;
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2020-04-10 19:33:09 +02:00
|
|
|
return (
|
2023-06-01 13:02:36 +02:00
|
|
|
<div style={{ ...theme.textStyle, marginBottom: 15 }}>
|
2020-04-10 19:33:09 +02:00
|
|
|
{description}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public sectionToComponent(key: string, section: any, settings: any, selected: boolean) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2019-12-13 03:16:34 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const createSettingComponents = (advanced: boolean) => {
|
2019-12-13 03:16:34 +02:00
|
|
|
const output = [];
|
2021-01-20 00:58:09 +02:00
|
|
|
|
2019-12-13 03:16:34 +02:00
|
|
|
for (let i = 0; i < section.metadatas.length; i++) {
|
|
|
|
const md = section.metadatas[i];
|
|
|
|
if (!!md.advanced !== advanced) continue;
|
|
|
|
const settingComp = this.settingToComponent(md.key, settings[md.key]);
|
|
|
|
output.push(settingComp);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
};
|
2019-01-28 01:15:56 +02:00
|
|
|
|
2019-12-13 03:16:34 +02:00
|
|
|
const settingComps = createSettingComponents(false);
|
|
|
|
const advancedSettingComps = createSettingComponents(true);
|
2019-01-28 01:15:56 +02:00
|
|
|
|
2021-01-20 00:58:09 +02:00
|
|
|
const sectionWidths: Record<string, any> = {
|
|
|
|
plugins: '100%',
|
2021-01-07 18:30:53 +02:00
|
|
|
};
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const sectionStyle: any = {
|
2019-09-11 01:53:01 +02:00
|
|
|
marginTop: 20,
|
2019-01-28 01:15:56 +02:00
|
|
|
marginBottom: 20,
|
2021-01-07 18:30:53 +02:00
|
|
|
maxWidth: sectionWidths[section.name] ? sectionWidths[section.name] : 640,
|
2019-01-28 01:15:56 +02:00
|
|
|
};
|
|
|
|
|
2019-09-11 01:53:01 +02:00
|
|
|
if (!selected) sectionStyle.display = 'none';
|
2019-02-10 18:29:06 +02:00
|
|
|
|
2019-01-28 01:15:56 +02:00
|
|
|
if (section.name === 'general') {
|
|
|
|
sectionStyle.borderTopWidth = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-08 00:50:12 +02:00
|
|
|
if (section.name === 'sync') {
|
|
|
|
const syncTargetMd = SyncTargetRegistry.idToMetadata(settings['sync.target']);
|
2023-06-01 13:02:36 +02:00
|
|
|
const statusStyle = { ...theme.textStyle, marginTop: 10 };
|
2023-08-14 19:12:49 +02:00
|
|
|
const warningStyle = { ...theme.textStyle, color: theme.colorWarn };
|
|
|
|
|
|
|
|
// Don't show the missing password warning if the user just changed the sync target (but hasn't
|
|
|
|
// saved yet).
|
|
|
|
const matchesSavedTarget = settings['sync.target'] === this.props.settings['sync.target'];
|
|
|
|
if (matchesSavedTarget && shouldShowMissingPasswordWarning(settings['sync.target'], settings)) {
|
|
|
|
settingComps.push(
|
|
|
|
<p key='missing-password-warning' style={warningStyle}>
|
2023-08-19 10:17:25 +02:00
|
|
|
{_('%s: Missing password.', _('Warning'))}
|
|
|
|
{' '}
|
|
|
|
<MacOSMissingPasswordHelpLink
|
|
|
|
theme={theme}
|
|
|
|
text={_('Help')}
|
|
|
|
/>
|
2023-08-23 19:28:00 +02:00
|
|
|
</p>,
|
2023-08-14 19:12:49 +02:00
|
|
|
);
|
|
|
|
}
|
2019-05-08 00:50:12 +02:00
|
|
|
|
|
|
|
if (syncTargetMd.supportsConfigCheck) {
|
|
|
|
const messages = shared.checkSyncConfigMessages(this);
|
|
|
|
const statusComp = !messages.length ? null : (
|
|
|
|
<div style={statusStyle}>
|
|
|
|
{messages[0]}
|
2019-07-29 14:13:23 +02:00
|
|
|
{messages.length >= 1 ? <p>{messages[1]}</p> : null}
|
|
|
|
</div>
|
|
|
|
);
|
2019-05-08 00:50:12 +02:00
|
|
|
|
|
|
|
settingComps.push(
|
|
|
|
<div key="check_sync_config_button" style={this.rowStyle_}>
|
2020-09-15 15:01:07 +02:00
|
|
|
<Button
|
|
|
|
title={_('Check synchronisation configuration')}
|
|
|
|
level={ButtonLevel.Secondary}
|
|
|
|
disabled={this.state.checkSyncConfigResult === 'checking'}
|
|
|
|
onClick={this.checkSyncConfig_}
|
|
|
|
/>
|
2019-07-29 14:13:23 +02:00
|
|
|
{statusComp}
|
2023-08-23 19:28:00 +02:00
|
|
|
</div>,
|
2019-07-29 14:13:23 +02:00
|
|
|
);
|
2019-05-08 00:50:12 +02:00
|
|
|
}
|
2019-12-13 03:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let advancedSettingsButton = null;
|
2020-03-14 01:46:14 +02:00
|
|
|
const advancedSettingsSectionStyle = { display: 'none' };
|
2019-12-13 03:16:34 +02:00
|
|
|
|
|
|
|
if (advancedSettingComps.length) {
|
2020-09-15 15:01:07 +02:00
|
|
|
advancedSettingsButton = (
|
2023-08-08 16:50:51 +02:00
|
|
|
<ToggleAdvancedSettingsButton
|
|
|
|
onClick={() => shared.advancedSettingsButton_click(this)}
|
|
|
|
advancedSettingsVisible={this.state.showAdvancedSettings}
|
|
|
|
/>
|
2020-09-15 15:01:07 +02:00
|
|
|
);
|
2019-12-13 03:16:34 +02:00
|
|
|
advancedSettingsSectionStyle.display = this.state.showAdvancedSettings ? 'block' : 'none';
|
2019-05-08 00:50:12 +02:00
|
|
|
}
|
|
|
|
|
2019-01-28 01:15:56 +02:00
|
|
|
return (
|
|
|
|
<div key={key} style={sectionStyle}>
|
2020-04-10 19:33:09 +02:00
|
|
|
{this.renderSectionDescription(section)}
|
2019-07-29 14:13:23 +02:00
|
|
|
<div>{settingComps}</div>
|
2019-12-13 03:16:34 +02:00
|
|
|
{advancedSettingsButton}
|
|
|
|
<div style={advancedSettingsSectionStyle}>{advancedSettingComps}</div>
|
2019-01-28 01:15:56 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
private labelStyle(themeId: number) {
|
|
|
|
const theme = themeStyle(themeId);
|
2023-06-01 13:02:36 +02:00
|
|
|
return { ...theme.textStyle, display: 'block',
|
2020-11-19 14:34:49 +02:00
|
|
|
color: theme.color,
|
|
|
|
fontSize: theme.fontSize * 1.083333,
|
|
|
|
fontWeight: 500,
|
2023-06-01 13:02:36 +02:00
|
|
|
marginBottom: theme.mainPadding / 2 };
|
2020-11-19 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private descriptionStyle(themeId: number) {
|
|
|
|
const theme = themeStyle(themeId);
|
2023-06-01 13:02:36 +02:00
|
|
|
return { ...theme.textStyle, color: theme.colorFaded,
|
2020-11-19 14:34:49 +02:00
|
|
|
fontStyle: 'italic',
|
|
|
|
maxWidth: '70em',
|
2023-06-01 13:02:36 +02:00
|
|
|
marginTop: 5 };
|
2020-11-19 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private renderLabel(themeId: number, label: string) {
|
|
|
|
const labelStyle = this.labelStyle(themeId);
|
|
|
|
return (
|
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{label}</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-20 00:58:09 +02:00
|
|
|
private renderHeader(themeId: number, label: string, style: any = null) {
|
2021-01-09 15:14:39 +02:00
|
|
|
const theme = themeStyle(themeId);
|
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const labelStyle = { ...theme.textStyle, display: 'block',
|
2021-01-09 15:14:39 +02:00
|
|
|
color: theme.color,
|
|
|
|
fontSize: theme.fontSize * 1.25,
|
|
|
|
fontWeight: 500,
|
|
|
|
marginBottom: theme.mainPadding,
|
2023-06-01 13:02:36 +02:00
|
|
|
...style };
|
2021-01-09 15:14:39 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{label}</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
private renderDescription(themeId: number, description: string) {
|
|
|
|
return description ? <div style={this.descriptionStyle(themeId)}>{description}</div> : null;
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public settingToComponent(key: string, value: any) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const output: any = null;
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const rowStyle = {
|
2021-01-07 18:30:53 +02:00
|
|
|
marginBottom: theme.mainPadding * 1.5,
|
2020-09-15 15:01:07 +02:00
|
|
|
};
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
const labelStyle = this.labelStyle(this.props.themeId);
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const subLabel = { ...labelStyle, display: 'block',
|
2019-01-30 21:19:06 +02:00
|
|
|
opacity: 0.7,
|
2023-06-01 13:02:36 +02:00
|
|
|
marginBottom: labelStyle.marginBottom };
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const checkboxLabelStyle = { ...labelStyle, marginLeft: 8,
|
2020-09-15 15:01:07 +02:00
|
|
|
display: 'inline',
|
2023-06-01 13:02:36 +02:00
|
|
|
backgroundColor: 'transparent' };
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
const controlStyle = {
|
|
|
|
display: 'inline-block',
|
2018-11-08 00:37:13 +02:00
|
|
|
color: theme.color,
|
2020-09-15 15:01:07 +02:00
|
|
|
fontFamily: theme.fontFamily,
|
2018-11-08 00:37:13 +02:00
|
|
|
backgroundColor: theme.backgroundColor,
|
2017-11-12 02:44:26 +02:00
|
|
|
};
|
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const textInputBaseStyle = { ...controlStyle, fontFamily: theme.fontFamily,
|
2019-09-11 01:53:01 +02:00
|
|
|
border: '1px solid',
|
|
|
|
padding: '4px 6px',
|
2020-09-15 15:01:07 +02:00
|
|
|
boxSizing: 'border-box',
|
|
|
|
borderColor: theme.borderColor4,
|
|
|
|
borderRadius: 3,
|
|
|
|
paddingLeft: 6,
|
|
|
|
paddingRight: 6,
|
|
|
|
paddingTop: 4,
|
2023-06-01 13:02:36 +02:00
|
|
|
paddingBottom: 4 };
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const updateSettingValue = (key: string, value: any) => {
|
2020-11-19 14:34:49 +02:00
|
|
|
const md = Setting.settingMetadata(key);
|
|
|
|
if (md.needRestart) {
|
|
|
|
this.setState({ needRestart: true });
|
|
|
|
}
|
|
|
|
shared.updateSettingValue(this, key, value);
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
if (md.autoSave) {
|
|
|
|
shared.scheduleSaveSettings(this);
|
|
|
|
}
|
|
|
|
};
|
2017-11-30 20:36:26 +02:00
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
const md = Setting.settingMetadata(key);
|
|
|
|
|
2021-06-19 18:32:36 +02:00
|
|
|
const descriptionText = Setting.keyDescription(key, AppType.Desktop);
|
2020-11-19 14:34:49 +02:00
|
|
|
const descriptionComp = this.renderDescription(this.props.themeId, descriptionText);
|
2018-03-02 20:16:48 +02:00
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
if (settingKeyToControl[key]) {
|
|
|
|
const SettingComponent = settingKeyToControl[key];
|
2021-01-07 18:30:53 +02:00
|
|
|
const label = md.label ? this.renderLabel(this.props.themeId, md.label()) : null;
|
2020-11-19 14:34:49 +02:00
|
|
|
return (
|
|
|
|
<div key={key} style={rowStyle}>
|
2021-01-07 18:30:53 +02:00
|
|
|
{label}
|
2020-11-19 14:34:49 +02:00
|
|
|
{this.renderDescription(this.props.themeId, md.description ? md.description() : null)}
|
|
|
|
<SettingComponent
|
|
|
|
metadata={md}
|
|
|
|
value={value}
|
|
|
|
themeId={this.props.themeId}
|
|
|
|
onChange={(event: any) => {
|
|
|
|
updateSettingValue(key, event.value);
|
|
|
|
}}
|
2021-01-07 18:30:53 +02:00
|
|
|
renderLabel={this.renderLabel}
|
|
|
|
renderDescription={this.renderDescription}
|
2021-01-09 15:14:39 +02:00
|
|
|
renderHeader={this.renderHeader}
|
2020-11-19 14:34:49 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (md.isEnum) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const items = [];
|
2017-11-12 02:44:26 +02:00
|
|
|
const settingOptions = md.options();
|
2022-05-05 14:19:23 +02:00
|
|
|
const array = Setting.enumOptionsToValueLabels(settingOptions, md.optionsOrder ? md.optionsOrder() : [], {
|
|
|
|
valueKey: 'key',
|
|
|
|
labelKey: 'label',
|
|
|
|
});
|
|
|
|
|
2017-12-17 13:30:32 +02:00
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
|
|
const e = array[i];
|
2019-07-29 14:13:23 +02:00
|
|
|
items.push(
|
|
|
|
<option value={e.key.toString()} key={e.key}>
|
|
|
|
{settingOptions[e.key]}
|
2023-08-23 19:28:00 +02:00
|
|
|
</option>,
|
2019-07-29 14:13:23 +02:00
|
|
|
);
|
2017-11-12 02:44:26 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const selectStyle = { ...controlStyle, paddingLeft: 6,
|
2020-09-15 15:01:07 +02:00
|
|
|
paddingRight: 6,
|
|
|
|
paddingTop: 4,
|
|
|
|
paddingBottom: 4,
|
|
|
|
borderColor: theme.borderColor4,
|
2023-06-01 13:02:36 +02:00
|
|
|
borderRadius: 3 };
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
return (
|
2017-12-15 09:31:57 +02:00
|
|
|
<div key={key} style={rowStyle}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{md.label()}</label>
|
|
|
|
</div>
|
|
|
|
<select
|
|
|
|
value={value}
|
2019-09-11 01:53:01 +02:00
|
|
|
style={selectStyle}
|
2020-11-12 21:13:28 +02:00
|
|
|
onChange={(event: any) => {
|
2019-07-29 14:13:23 +02:00
|
|
|
updateSettingValue(key, event.target.value);
|
|
|
|
}}
|
|
|
|
>
|
2017-11-12 02:44:26 +02:00
|
|
|
{items}
|
|
|
|
</select>
|
2019-07-29 14:13:23 +02:00
|
|
|
{descriptionComp}
|
2017-11-12 02:44:26 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (md.type === Setting.TYPE_BOOL) {
|
2019-09-13 00:16:42 +02:00
|
|
|
const onCheckboxClick = () => {
|
2019-07-29 14:13:23 +02:00
|
|
|
updateSettingValue(key, !value);
|
|
|
|
};
|
2017-12-08 00:29:02 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const checkboxSize = theme.fontSize * 1.1666666666666;
|
|
|
|
|
2018-01-23 20:31:49 +02:00
|
|
|
// Hack: The {key+value.toString()} is needed as otherwise the checkbox doesn't update when the state changes.
|
|
|
|
// There's probably a better way to do this but can't figure it out.
|
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
return (
|
2021-01-20 00:58:09 +02:00
|
|
|
<div key={key + (`${value}`).toString()} style={rowStyle}>
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={{ ...controlStyle, backgroundColor: 'transparent', display: 'flex', alignItems: 'center' }}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<input
|
2019-09-19 23:51:18 +02:00
|
|
|
id={`setting_checkbox_${key}`}
|
2019-07-29 14:13:23 +02:00
|
|
|
type="checkbox"
|
|
|
|
checked={!!value}
|
2020-09-15 15:01:07 +02:00
|
|
|
onChange={() => {
|
|
|
|
onCheckboxClick();
|
2019-07-29 14:13:23 +02:00
|
|
|
}}
|
2020-09-15 15:01:07 +02:00
|
|
|
style={{ marginLeft: 0, width: checkboxSize, height: checkboxSize }}
|
2019-07-29 14:13:23 +02:00
|
|
|
/>
|
|
|
|
<label
|
2020-09-15 15:01:07 +02:00
|
|
|
onClick={() => {
|
|
|
|
onCheckboxClick();
|
2019-07-29 14:13:23 +02:00
|
|
|
}}
|
2020-09-15 15:01:07 +02:00
|
|
|
style={{ ...checkboxLabelStyle, marginLeft: 5, marginBottom: 0 }}
|
2019-09-19 23:51:18 +02:00
|
|
|
htmlFor={`setting_checkbox_${key}`}
|
2019-07-29 14:13:23 +02:00
|
|
|
>
|
|
|
|
{md.label()}
|
|
|
|
</label>
|
2017-11-12 02:44:26 +02:00
|
|
|
</div>
|
2020-09-15 15:01:07 +02:00
|
|
|
{descriptionComp}
|
2017-11-12 02:44:26 +02:00
|
|
|
</div>
|
|
|
|
);
|
2017-12-08 00:29:02 +02:00
|
|
|
} else if (md.type === Setting.TYPE_STRING) {
|
2023-06-01 13:02:36 +02:00
|
|
|
const inputStyle: any = { ...textInputBaseStyle, width: '50%',
|
|
|
|
minWidth: '20em' };
|
2018-01-26 00:44:09 +02:00
|
|
|
const inputType = md.secure === true ? 'password' : 'text';
|
|
|
|
|
2022-04-20 17:21:00 +02:00
|
|
|
if (md.subType === 'file_path_and_args' || md.subType === 'file_path' || md.subType === 'directory_path') {
|
2019-01-30 21:19:06 +02:00
|
|
|
inputStyle.marginBottom = subLabel.marginBottom;
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const splitCmd = (cmdString: string) => {
|
2023-01-17 17:34:04 +02:00
|
|
|
// Normally not necessary but certain plugins found a way to
|
|
|
|
// set the set the value to "undefined", leading to a crash.
|
|
|
|
// This is now fixed at the model level but to be sure we
|
|
|
|
// check here too, to handle any already existing data.
|
|
|
|
// https://github.com/laurent22/joplin/issues/7621
|
|
|
|
if (!cmdString) cmdString = '';
|
2019-01-30 21:19:06 +02:00
|
|
|
const path = pathUtils.extractExecutablePath(cmdString);
|
|
|
|
const args = cmdString.substr(path.length + 1);
|
|
|
|
return [pathUtils.unquotePath(path), args];
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const joinCmd = (cmdArray: string[]) => {
|
2019-01-30 21:19:06 +02:00
|
|
|
if (!cmdArray[0] && !cmdArray[1]) return '';
|
|
|
|
let cmdString = pathUtils.quotePath(cmdArray[0]);
|
|
|
|
if (!cmdString) cmdString = '""';
|
2019-09-19 23:51:18 +02:00
|
|
|
if (cmdArray[1]) cmdString += ` ${cmdArray[1]}`;
|
2019-01-30 21:19:06 +02:00
|
|
|
return cmdString;
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const onPathChange = (event: any) => {
|
2023-01-05 13:05:23 +02:00
|
|
|
if (md.subType === 'file_path_and_args') {
|
|
|
|
const cmd = splitCmd(this.state.settings[key]);
|
|
|
|
cmd[0] = event.target.value;
|
|
|
|
updateSettingValue(key, joinCmd(cmd));
|
|
|
|
} else {
|
|
|
|
updateSettingValue(key, event.target.value);
|
|
|
|
}
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const onArgsChange = (event: any) => {
|
2019-01-30 21:19:06 +02:00
|
|
|
const cmd = splitCmd(this.state.settings[key]);
|
|
|
|
cmd[1] = event.target.value;
|
|
|
|
updateSettingValue(key, joinCmd(cmd));
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2021-11-01 09:38:06 +02:00
|
|
|
const browseButtonClick = async () => {
|
2022-04-20 17:21:00 +02:00
|
|
|
if (md.subType === 'directory_path') {
|
|
|
|
const paths = await bridge().showOpenDialog({
|
|
|
|
properties: ['openDirectory'],
|
|
|
|
});
|
|
|
|
if (!paths || !paths.length) return;
|
|
|
|
updateSettingValue(key, paths[0]);
|
|
|
|
} else {
|
|
|
|
const paths = await bridge().showOpenDialog();
|
|
|
|
if (!paths || !paths.length) return;
|
2022-08-29 16:27:19 +02:00
|
|
|
|
|
|
|
if (md.subType === 'file_path') {
|
|
|
|
updateSettingValue(key, paths[0]);
|
|
|
|
} else {
|
|
|
|
const cmd = splitCmd(this.state.settings[key]);
|
|
|
|
cmd[0] = paths[0];
|
|
|
|
updateSettingValue(key, joinCmd(cmd));
|
|
|
|
}
|
2022-04-20 17:21:00 +02:00
|
|
|
}
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
|
|
|
const cmd = splitCmd(this.state.settings[key]);
|
2022-08-29 16:27:19 +02:00
|
|
|
const path = md.subType === 'file_path_and_args' ? cmd[0] : this.state.settings[key];
|
2019-01-30 21:19:06 +02:00
|
|
|
|
2022-04-20 17:21:00 +02:00
|
|
|
const argComp = md.subType !== 'file_path_and_args' ? null : (
|
|
|
|
<div style={{ ...rowStyle, marginBottom: 5 }}>
|
|
|
|
<div style={subLabel}>{_('Arguments:')}</div>
|
|
|
|
<input
|
|
|
|
type={inputType}
|
|
|
|
style={inputStyle}
|
|
|
|
onChange={(event: any) => {
|
|
|
|
onArgsChange(event);
|
|
|
|
}}
|
|
|
|
value={cmd[1]}
|
|
|
|
spellCheck={false}
|
|
|
|
/>
|
|
|
|
<div style={{ width: inputStyle.width, minWidth: inputStyle.minWidth }}>
|
|
|
|
{descriptionComp}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2019-01-30 21:19:06 +02:00
|
|
|
return (
|
|
|
|
<div key={key} style={rowStyle}>
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{md.label()}</label>
|
|
|
|
</div>
|
2019-07-29 14:13:23 +02:00
|
|
|
<div style={{ display: 'flex' }}>
|
|
|
|
<div style={{ flex: 1 }}>
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={{ ...rowStyle, marginBottom: 5 }}>
|
2021-01-21 20:23:32 +02:00
|
|
|
<div style={subLabel}>{_('Path:')}</div>
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: inputStyle.marginBottom }}>
|
|
|
|
<input
|
|
|
|
type={inputType}
|
2023-06-01 13:02:36 +02:00
|
|
|
style={{ ...inputStyle, marginBottom: 0, marginRight: 5 }}
|
2020-11-12 21:13:28 +02:00
|
|
|
onChange={(event: any) => {
|
2020-09-15 15:01:07 +02:00
|
|
|
onPathChange(event);
|
|
|
|
}}
|
2022-08-29 16:27:19 +02:00
|
|
|
value={path}
|
2020-11-16 18:20:26 +02:00
|
|
|
spellCheck={false}
|
2020-09-15 15:01:07 +02:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
level={ButtonLevel.Secondary}
|
|
|
|
title={_('Browse...')}
|
|
|
|
onClick={browseButtonClick}
|
2021-10-03 17:00:49 +02:00
|
|
|
size={ButtonSize.Small}
|
2020-09-15 15:01:07 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-30 21:19:06 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-20 17:21:00 +02:00
|
|
|
{argComp}
|
2019-01-30 21:19:06 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
2020-11-12 21:13:28 +02:00
|
|
|
const onTextChange = (event: any) => {
|
2019-01-30 21:19:06 +02:00
|
|
|
updateSettingValue(key, event.target.value);
|
2019-07-29 14:13:23 +02:00
|
|
|
};
|
2019-01-30 21:19:06 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={key} style={rowStyle}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{md.label()}</label>
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type={inputType}
|
|
|
|
style={inputStyle}
|
|
|
|
value={this.state.settings[key]}
|
2020-11-12 21:13:28 +02:00
|
|
|
onChange={(event: any) => {
|
2019-07-29 14:13:23 +02:00
|
|
|
onTextChange(event);
|
|
|
|
}}
|
2020-11-16 18:20:26 +02:00
|
|
|
spellCheck={false}
|
2019-07-29 14:13:23 +02:00
|
|
|
/>
|
2021-01-20 00:58:09 +02:00
|
|
|
<div style={{ width: inputStyle.width, minWidth: inputStyle.minWidth }}>
|
2020-09-15 15:01:07 +02:00
|
|
|
{descriptionComp}
|
|
|
|
</div>
|
2019-01-30 21:19:06 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-01-19 14:27:44 +02:00
|
|
|
} else if (md.type === Setting.TYPE_INT) {
|
2020-11-12 21:13:28 +02:00
|
|
|
const onNumChange = (event: any) => {
|
2018-01-23 20:31:49 +02:00
|
|
|
updateSettingValue(key, event.target.value);
|
2018-01-19 14:27:44 +02:00
|
|
|
};
|
|
|
|
|
2019-05-06 22:35:29 +02:00
|
|
|
const label = [md.label()];
|
2019-09-19 23:51:18 +02:00
|
|
|
if (md.unitLabel) label.push(`(${md.unitLabel()})`);
|
2019-05-06 22:35:29 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const inputStyle: any = { ...textInputBaseStyle };
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2018-01-19 14:27:44 +02:00
|
|
|
return (
|
2018-01-23 20:31:49 +02:00
|
|
|
<div key={key} style={rowStyle}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{label.join(' ')}</label>
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
type="number"
|
2019-09-11 01:53:01 +02:00
|
|
|
style={inputStyle}
|
2019-07-29 14:13:23 +02:00
|
|
|
value={this.state.settings[key]}
|
2020-11-12 21:13:28 +02:00
|
|
|
onChange={(event: any) => {
|
2019-07-29 14:13:23 +02:00
|
|
|
onNumChange(event);
|
|
|
|
}}
|
|
|
|
min={md.minimum}
|
|
|
|
max={md.maximum}
|
|
|
|
step={md.step}
|
2020-11-16 18:20:26 +02:00
|
|
|
spellCheck={false}
|
2019-07-29 14:13:23 +02:00
|
|
|
/>
|
|
|
|
{descriptionComp}
|
2018-01-23 20:31:49 +02:00
|
|
|
</div>
|
2018-01-19 14:27:44 +02:00
|
|
|
);
|
2019-12-13 02:40:58 +02:00
|
|
|
} else if (md.type === Setting.TYPE_BUTTON) {
|
2021-08-16 16:20:14 +02:00
|
|
|
const labelComp = md.hideLabel ? null : (
|
|
|
|
<div style={labelStyle}>
|
|
|
|
<label>{md.label()}</label>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2019-12-13 02:40:58 +02:00
|
|
|
return (
|
|
|
|
<div key={key} style={rowStyle}>
|
2021-08-16 16:20:14 +02:00
|
|
|
{labelComp}
|
2021-05-03 12:55:38 +02:00
|
|
|
<Button level={ButtonLevel.Secondary} title={md.label()} onClick={md.onClick ? md.onClick : () => this.handleSettingButton(key)}/>
|
2019-12-13 02:40:58 +02:00
|
|
|
{descriptionComp}
|
|
|
|
</div>
|
|
|
|
);
|
2017-12-08 00:29:02 +02:00
|
|
|
} else {
|
2019-09-19 23:51:18 +02:00
|
|
|
console.warn(`Type not implemented: ${key}`);
|
2017-11-12 02:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
private restartMessage() {
|
|
|
|
return _('The application must be restarted for these changes to take effect.');
|
|
|
|
}
|
|
|
|
|
|
|
|
private async restartApp() {
|
|
|
|
await Setting.saveAll();
|
2022-04-20 18:34:58 +02:00
|
|
|
await restart();
|
2020-11-19 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private async checkNeedRestart() {
|
|
|
|
if (this.state.needRestart) {
|
|
|
|
const doItNow = await bridge().showConfirmMessageBox(this.restartMessage(), {
|
|
|
|
buttons: [_('Do it now'), _('Later')],
|
|
|
|
});
|
|
|
|
|
|
|
|
if (doItNow) await this.restartApp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public async onApplyClick() {
|
2024-01-27 20:20:51 +02:00
|
|
|
const done = await shared.saveSettings(this);
|
|
|
|
if (!done) return;
|
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
await this.checkNeedRestart();
|
2018-06-26 00:54:28 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public async onSaveClick() {
|
2024-01-27 20:20:51 +02:00
|
|
|
const done = await shared.saveSettings(this);
|
|
|
|
if (!done) return;
|
2020-11-19 14:34:49 +02:00
|
|
|
await this.checkNeedRestart();
|
2017-12-08 00:29:02 +02:00
|
|
|
this.props.dispatch({ type: 'NAV_BACK' });
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public onCancelClick() {
|
2017-12-08 00:29:02 +02:00
|
|
|
this.props.dispatch({ type: 'NAV_BACK' });
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public hasChanges() {
|
2019-09-11 01:53:01 +02:00
|
|
|
return !!this.state.changedSettingKeys.length;
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public render() {
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
2019-01-28 01:44:16 +02:00
|
|
|
|
2023-06-01 13:02:36 +02:00
|
|
|
const style = {
|
|
|
|
...this.props.style,
|
|
|
|
overflow: 'hidden',
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
backgroundColor: theme.backgroundColor3,
|
|
|
|
};
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const settings = this.state.settings;
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const containerStyle = {
|
|
|
|
overflow: 'auto',
|
|
|
|
padding: theme.configScreenPadding,
|
|
|
|
paddingTop: 0,
|
|
|
|
display: 'flex',
|
|
|
|
flex: 1,
|
|
|
|
};
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2019-09-11 01:53:01 +02:00
|
|
|
const hasChanges = this.hasChanges();
|
2019-01-28 01:44:16 +02:00
|
|
|
|
2023-11-09 21:19:08 +02:00
|
|
|
const settingComps = shared.settingsToComponents2(this, AppType.Desktop, settings, this.state.selectedSectionName);
|
2017-11-12 02:44:26 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
// screenComp is a custom config screen, such as the encryption config screen or keymap config screen.
|
|
|
|
// These screens handle their own loading/saving of settings and have bespoke rendering.
|
|
|
|
// When screenComp is null, it means we are viewing the regular settings.
|
2021-10-03 17:00:49 +02:00
|
|
|
const screenComp = this.state.screenName ? <div className="config-screen-content-wrapper" style={{ overflow: 'scroll', flex: 1 }}>{this.screenFromName(this.state.screenName)}</div> : null;
|
2019-09-11 01:53:01 +02:00
|
|
|
|
|
|
|
if (screenComp) containerStyle.display = 'none';
|
|
|
|
|
2023-11-09 21:19:08 +02:00
|
|
|
const sections = shared.settingsSections({ device: AppType.Desktop, settings });
|
2019-09-11 01:53:01 +02:00
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
const needRestartComp: any = this.state.needRestart ? (
|
|
|
|
<div style={{ ...theme.textStyle, padding: 10, paddingLeft: 24, backgroundColor: theme.warningBackgroundColor, color: theme.color }}>
|
|
|
|
{this.restartMessage()}
|
2020-11-25 16:40:25 +02:00
|
|
|
<a style={{ ...theme.urlStyle, marginLeft: 10 }} href="#" onClick={() => { void this.restartApp(); }}>{_('Restart now')}</a>
|
2020-11-19 14:34:49 +02:00
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
|
2021-02-07 14:55:28 +02:00
|
|
|
const rightStyle = { ...style, flex: 1 };
|
|
|
|
delete style.width;
|
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
return (
|
2021-10-03 17:00:49 +02:00
|
|
|
<div className="config-screen" style={{ display: 'flex', flexDirection: 'row', height: this.props.style.height }}>
|
2021-01-12 14:28:55 +02:00
|
|
|
<Sidebar
|
2019-09-11 01:53:01 +02:00
|
|
|
selection={this.state.selectedSectionName}
|
2021-01-12 14:28:55 +02:00
|
|
|
onSelectionChange={this.sidebar_selectionChange}
|
2019-09-11 01:53:01 +02:00
|
|
|
sections={sections}
|
|
|
|
/>
|
2021-02-07 14:55:28 +02:00
|
|
|
<div style={rightStyle}>
|
2020-09-15 15:01:07 +02:00
|
|
|
{screenComp}
|
2020-11-19 14:34:49 +02:00
|
|
|
{needRestartComp}
|
2020-09-15 15:01:07 +02:00
|
|
|
<div style={containerStyle}>{settingComps}</div>
|
|
|
|
<ButtonBar
|
|
|
|
hasChanges={hasChanges}
|
|
|
|
backButtonTitle={hasChanges && !screenComp ? _('Cancel') : _('Back')}
|
|
|
|
onCancelClick={this.onCancelClick}
|
|
|
|
onSaveClick={screenComp ? null : this.onSaveClick}
|
|
|
|
onApplyClick={screenComp ? null : this.onApplyClick}
|
|
|
|
/>
|
2019-02-10 18:29:06 +02:00
|
|
|
</div>
|
2017-11-12 02:44:26 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
const mapStateToProps = (state: any) => {
|
2017-11-12 02:44:26 +02:00
|
|
|
return {
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: state.settings.theme,
|
2017-11-12 02:44:26 +02:00
|
|
|
settings: state.settings,
|
|
|
|
locale: state.settings.locale,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
export default connect(mapStateToProps)(ConfigScreenComponent);
|
2017-11-12 02:44:26 +02:00
|
|
|
|