import React, { useEffect } from 'react' import capitalize from 'lodash/capitalize' import { Header, Card, Row, Col, Switch, ButtonSelect, ButtonSelectOptions, Input, Icon } from '@components' import { useI18n, useClashXData, useAPIInfo, useGeneral, useIdentity } from '@stores' import { updateConfig } from '@lib/request' import { useObject } from '@lib/hook' import { isClashX, jsBridge } from '@lib/jsBridge' import { Lang } from '@i18n' import './style.scss' const languageOptions: ButtonSelectOptions[] = [{ label: '中文', value: 'zh_CN' }, { label: 'English', value: 'en_US' }] export default function Settings () { const { data: clashXData, update: fetchClashXData } = useClashXData() const { general, update: fetchGeneral } = useGeneral() const { set: setIdentity } = useIdentity() const { data: apiInfo } = useAPIInfo() const { useTranslation, setLang, lang } = useI18n() const { t } = useTranslation('Settings') const [info, set] = useObject({ socks5ProxyPort: 7891, httpProxyPort: 7890, isClashX: false }) useEffect(() => { fetchGeneral() if (isClashX()) { fetchClashXData().then(() => set('isClashX', true)) } }, []) useEffect(() => { set('socks5ProxyPort', general.socksPort) set('httpProxyPort', general.port) }, [general]) async function handleProxyModeChange (mode: string) { await updateConfig({ mode }) await fetchGeneral() } async function handleStartAtLoginChange (state: boolean) { await jsBridge.setStartAtLogin(state) fetchClashXData() } async function handleSetSystemProxy (state: boolean) { await jsBridge.setSystemProxy(state) fetchClashXData() } function changeLanguage (language: Lang) { setLang(language) } async function handleHttpPortSave () { await updateConfig({ port: info.httpProxyPort }) await fetchGeneral() } async function handleSocksPortSave () { await updateConfig({ 'socks-port': info.socks5ProxyPort }) await fetchGeneral() } async function handleAllowLanChange (state: boolean) { await updateConfig({ 'allow-lan': state }) await fetchGeneral() } const { hostname: externalControllerHost, port: externalControllerPort } = apiInfo const { allowLan, mode } = general const { startAtLogin, systemProxy } = clashXData const proxyModeOptions: ButtonSelectOptions[] = [ { label: t('values.global'), value: 'Global' }, { label: t('values.rules'), value: 'Rule' }, { label: t('values.direct'), value: 'Direct' } ] return (
{t('versionString')}
{t('checkUpdate')}