Skip to content

Commit

Permalink
feat: Support dynamic acquisition of clash_mode (#908)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xireiki committed Aug 22, 2024
1 parent bd65478 commit 341a14a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ export enum TAILWINDCSS_SIZE {
LG = 'lg',
}

export enum MODE_OPTIONS {
Global = 'global',
Rule = 'rule',
Direct = 'direct',
}

export enum LOG_LEVEL {
Info = 'info',
Error = 'error',
Expand Down
14 changes: 10 additions & 4 deletions src/pages/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
upgradingUI,
} from '~/apis'
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 {
autoSwitchTheme,
Expand Down Expand Up @@ -179,6 +179,10 @@ const ConfigForm = () => {
}
})

const modes = () => {
return configsData()?.modes || ["rule", "direct", "global"]
}

return (
<div class="flex flex-col gap-4">
<select
Expand All @@ -188,9 +192,11 @@ const ConfigForm = () => {
void updateBackendConfigAPI('mode', e.target.value, refetch)
}
>
<option value={MODE_OPTIONS.Global}>{t('global')}</option>
<option value={MODE_OPTIONS.Rule}>{t('rule')}</option>
<option value={MODE_OPTIONS.Direct}>{t('direct')}</option>
<For echo={modes()}>
{(name) => (
<option value={name}>{t(name) ?? name}</option>
)}
</For>
</select>

<Show when={!isSingBox()}>
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export type Log = {
export type LogWithSeq = Log & { seq: number }

export type Config = {
mode: 'global' | 'rule' | 'direct'
mode: string
modes?: string[]
port: number
'socks-port': number
'redir-port': number
Expand Down

0 comments on commit 341a14a

Please sign in to comment.