mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
chore: identify sing-box (#373)
* chore: identify sing-box * feat(config): hide form elements when endpoint version is sing-box --------- Co-authored-by: kunish <kunish.butt@gmail.com>
This commit is contained in:
parent
ef1fa19e94
commit
79335831cb
@ -1,5 +1,9 @@
|
|||||||
import { createSignal } from 'solid-js'
|
import { createSignal } from 'solid-js'
|
||||||
|
|
||||||
|
export const isSingBox = (version: string) => {
|
||||||
|
return version.includes('sing-box')
|
||||||
|
}
|
||||||
|
|
||||||
export const transformEndpointURL = (url: string) =>
|
export const transformEndpointURL = (url: string) =>
|
||||||
/^https?/.test(url) ? url : `${window.location.protocol}//${url}`
|
/^https?/.test(url) ? url : `${window.location.protocol}//${url}`
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ import { createForm } from '@felte/solid'
|
|||||||
import { validator } from '@felte/validator-zod'
|
import { validator } from '@felte/validator-zod'
|
||||||
import { useNavigate } from '@solidjs/router'
|
import { useNavigate } from '@solidjs/router'
|
||||||
import {
|
import {
|
||||||
|
Accessor,
|
||||||
|
Component,
|
||||||
For,
|
For,
|
||||||
Show,
|
Show,
|
||||||
createEffect,
|
createEffect,
|
||||||
@ -29,6 +31,7 @@ import {
|
|||||||
} from '~/apis'
|
} from '~/apis'
|
||||||
import { Button, ConfigTitle } from '~/components'
|
import { Button, ConfigTitle } from '~/components'
|
||||||
import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants'
|
import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants'
|
||||||
|
import { isSingBox } from '~/helpers'
|
||||||
import { locale, setLocale, useI18n } from '~/i18n'
|
import { locale, setLocale, useI18n } from '~/i18n'
|
||||||
import {
|
import {
|
||||||
autoSwitchTheme,
|
autoSwitchTheme,
|
||||||
@ -114,7 +117,9 @@ const configFormSchema = z.object({
|
|||||||
'mixed-port': z.number(),
|
'mixed-port': z.number(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const ConfigForm = () => {
|
const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
|
||||||
|
backendVersion,
|
||||||
|
}) => {
|
||||||
const [t] = useI18n()
|
const [t] = useI18n()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
@ -196,6 +201,7 @@ const ConfigForm = () => {
|
|||||||
<option value={MODE_OPTIONS.Direct}>{t('direct')}</option>
|
<option value={MODE_OPTIONS.Direct}>{t('direct')}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<Show when={!isSingBox(backendVersion())}>
|
||||||
<form class="grid grid-cols-3 gap-2 sm:grid-cols-5" use:form={form}>
|
<form class="grid grid-cols-3 gap-2 sm:grid-cols-5" use:form={form}>
|
||||||
<For each={portList}>
|
<For each={portList}>
|
||||||
{(item) => (
|
{(item) => (
|
||||||
@ -299,6 +305,7 @@ const ConfigForm = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-2 sm:grid-cols-3">
|
<div class="grid grid-cols-2 gap-2 sm:grid-cols-3">
|
||||||
<Button
|
<Button
|
||||||
@ -325,6 +332,7 @@ const ConfigForm = () => {
|
|||||||
{t('flushFakeIP')}
|
{t('flushFakeIP')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Show when={!isSingBox(backendVersion())}>
|
||||||
<Button
|
<Button
|
||||||
class="btn-error"
|
class="btn-error"
|
||||||
loading={upgradingBackend()}
|
loading={upgradingBackend()}
|
||||||
@ -332,6 +340,7 @@ const ConfigForm = () => {
|
|||||||
>
|
>
|
||||||
{t('upgradeCore')}
|
{t('upgradeCore')}
|
||||||
</Button>
|
</Button>
|
||||||
|
</Show>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
class="btn-warning"
|
class="btn-warning"
|
||||||
@ -453,14 +462,13 @@ const ConfigForXd = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Versions = () => {
|
const Versions: Component<{ backendVersion: Accessor<string> }> = ({
|
||||||
const [backendVersion, setBackendVersion] = createSignal('')
|
backendVersion,
|
||||||
|
}) => {
|
||||||
const [isUpdateAvailable, setIsUpdateAvailable] = createSignal(false)
|
const [isUpdateAvailable, setIsUpdateAvailable] = createSignal(false)
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const version = await fetchBackendVersionAPI()
|
setIsUpdateAvailable(await isUpdateAvailableAPI(backendVersion()))
|
||||||
setBackendVersion(version)
|
|
||||||
setIsUpdateAvailable(await isUpdateAvailableAPI(version))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -486,17 +494,26 @@ const Versions = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const [backendVersion, setBackendVersion] = createSignal('')
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const version = await fetchBackendVersionAPI()
|
||||||
|
setBackendVersion(version)
|
||||||
|
})
|
||||||
|
|
||||||
const [t] = useI18n()
|
const [t] = useI18n()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="mx-auto flex max-w-screen-md flex-col gap-4">
|
<div class="mx-auto flex max-w-screen-md flex-col gap-4">
|
||||||
|
<Show when={!isSingBox(backendVersion())}>
|
||||||
<ConfigTitle withDivider>{t('dnsQuery')}</ConfigTitle>
|
<ConfigTitle withDivider>{t('dnsQuery')}</ConfigTitle>
|
||||||
|
|
||||||
<DNSQueryForm />
|
<DNSQueryForm />
|
||||||
|
</Show>
|
||||||
|
|
||||||
<ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle>
|
<ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle>
|
||||||
|
|
||||||
<ConfigForm />
|
<ConfigForm backendVersion={backendVersion} />
|
||||||
|
|
||||||
<ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle>
|
<ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle>
|
||||||
|
|
||||||
@ -504,7 +521,7 @@ export default () => {
|
|||||||
|
|
||||||
<ConfigTitle withDivider>{t('version')}</ConfigTitle>
|
<ConfigTitle withDivider>{t('version')}</ConfigTitle>
|
||||||
|
|
||||||
<Versions />
|
<Versions backendVersion={backendVersion} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user