import * as React from 'react';
import {
Cpu,
DownloadCloud,
LogOut,
Monitor,
RotateCw,
Settings,
Tool,
Trash2,
} from '~/components/shared/FeatherIcons';
import { useTranslation } from 'react-i18next';
import Select from '~/components/shared/Select';
import { useConfigPage } from '~/modules/config/hooks';
import {
CONFIG_CHART_STYLE_PROPS,
getBackendContent,
LANGUAGE_OPTIONS,
LOG_LEVEL_OPTIONS,
MODE_OPTIONS,
PORT_FIELDS,
TUN_STACK_OPTIONS,
} from '~/modules/config/utils';
import { ClashGeneralConfig, DispatchFn } from '~/store/types';
import { ClashAPIConfig } from '~/types';
import Button from './Button';
import s0 from './Config.module.scss';
import ContentHeader from './ContentHeader';
import Input, { SelfControlledInput } from './Input';
import { Selection2 } from './Selection';
import { useStoreActions } from './StateProvider';
import Switch from './SwitchThemed';
import TrafficChartSample from './TrafficChartSample';
type Props = {
dispatch: DispatchFn;
configs: ClashGeneralConfig;
selectedChartStyleIndex: number;
apiConfig: ClashAPIConfig;
};
export default function Config({
dispatch,
configs,
selectedChartStyleIndex,
apiConfig,
}: Props) {
const { t, i18n } = useTranslation();
const { selectChartStyleIndex, updateAppConfig } = useStoreActions();
const {
configState,
openAPIConfigModal,
handleInputOnChange,
handleInputOnBlur,
handleReloadConfigFile,
handleRestartCore,
handleUpgradeCore,
handleUpgradeGeo,
handleUpgradeUI,
handleFlushFakeIPPool,
versionQuery: { data: version },
} = useConfigPage({
apiConfig,
configs,
dispatch,
updateAppConfig,
});
return (
{t('general')}
{(version.meta && version.premium) ||
PORT_FIELDS.map((f) =>
configState[f.key] !== undefined ? (
) : null
)}
Mode
Log Level
{(version.meta && version.premium) || (
{t('allow_lan')}
handleInputOnChange({ name: 'allow-lan', value: value })
}
/>
)}
{version.meta && !version.premium && (
{t('tls_sniffing')}
handleInputOnChange({ name: 'sniffing', value: value })
}
/>
)}
{version.meta && (
<>
{version.premium || (
TUN
{t('enable_tun_device')}
handleInputOnChange({ name: 'enable', value: value })
}
/>
TUN IP Stack
)}
{t('management')}
Reload
}
label={t('reload_config_file')}
onClick={handleReloadConfigFile}
/>
{version.meta && !version.premium && (
GEO Databases
}
label={t('upgrade_geo')}
onClick={handleUpgradeGeo}
/>
)}
{version.meta && !version.premium && (
Dashboard UI
}
label={t('upgrade_ui')}
onClick={handleUpgradeUI}
/>
)}
FakeIP
}
label={t('flush_fake_ip_pool')}
onClick={handleFlushFakeIPPool}
/>
{version.meta && !version.premium && (
Restart
}
label={t('restart_core')}
onClick={handleRestartCore}
/>
)}
{version.meta && !version.premium && (
⚠️ Upgrade ⚠️
}
label={t('upgrade_core')}
onClick={handleUpgradeCore}
/>
)}
>
)}
{t('dashboard')}
{t('lang')}
{t('current_backend')}
{getBackendContent(version) + apiConfig?.baseURL}
Action
}
label={t('switch_backend')}
onClick={openAPIConfigModal}
/>
);
}