feat: Support dynamic acquisition of clash_mode (#908)

* feat: Dynamic clash_mode support

* fix: Constraint modes & implement part i18n

* refactor: Optimize select option generation logic & set modes default value

* feat: Some clash_mode keywords are translated using i18n

* refactor: Use For instead of JS map()

* refactor: Remove the MODE_OPTIONS enum
This commit is contained in:
xireiki 2024-08-22 16:44:30 +08:00 committed by GitHub
parent bd6547873f
commit 341a14a7bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 11 deletions

View File

@ -151,12 +151,6 @@ export enum TAILWINDCSS_SIZE {
LG = 'lg', LG = 'lg',
} }
export enum MODE_OPTIONS {
Global = 'global',
Rule = 'rule',
Direct = 'direct',
}
export enum LOG_LEVEL { export enum LOG_LEVEL {
Info = 'info', Info = 'info',
Error = 'error', Error = 'error',

View File

@ -21,7 +21,7 @@ import {
upgradingUI, upgradingUI,
} from '~/apis' } from '~/apis'
import { Button, ConfigTitle } from '~/components' import { Button, ConfigTitle } from '~/components'
import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants' import { LANG, ROUTES, themes } from '~/constants'
import { locale, setLocale, useI18n } from '~/i18n' import { locale, setLocale, useI18n } from '~/i18n'
import { import {
autoSwitchTheme, autoSwitchTheme,
@ -179,6 +179,10 @@ const ConfigForm = () => {
} }
}) })
const modes = () => {
return configsData()?.modes || ["rule", "direct", "global"]
}
return ( return (
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
<select <select
@ -188,9 +192,11 @@ const ConfigForm = () => {
void updateBackendConfigAPI('mode', e.target.value, refetch) void updateBackendConfigAPI('mode', e.target.value, refetch)
} }
> >
<option value={MODE_OPTIONS.Global}>{t('global')}</option> <For echo={modes()}>
<option value={MODE_OPTIONS.Rule}>{t('rule')}</option> {(name) => (
<option value={MODE_OPTIONS.Direct}>{t('direct')}</option> <option value={name}>{t(name) ?? name}</option>
)}
</For>
</select> </select>
<Show when={!isSingBox()}> <Show when={!isSingBox()}>

View File

@ -117,7 +117,8 @@ export type Log = {
export type LogWithSeq = Log & { seq: number } export type LogWithSeq = Log & { seq: number }
export type Config = { export type Config = {
mode: 'global' | 'rule' | 'direct' mode: string
modes?: string[]
port: number port: number
'socks-port': number 'socks-port': number
'redir-port': number 'redir-port': number