From 79335831cbe748644f73f73bcf9caecd028798ad Mon Sep 17 00:00:00 2001 From: yaotthaha Date: Mon, 16 Oct 2023 20:26:16 +0800 Subject: [PATCH] chore: identify sing-box (#373) * chore: identify sing-box * feat(config): hide form elements when endpoint version is sing-box --------- Co-authored-by: kunish --- src/helpers/global.ts | 4 + src/pages/Config.tsx | 249 ++++++++++++++++++++++-------------------- 2 files changed, 137 insertions(+), 116 deletions(-) diff --git a/src/helpers/global.ts b/src/helpers/global.ts index 9dd8373..4c75bed 100644 --- a/src/helpers/global.ts +++ b/src/helpers/global.ts @@ -1,5 +1,9 @@ import { createSignal } from 'solid-js' +export const isSingBox = (version: string) => { + return version.includes('sing-box') +} + export const transformEndpointURL = (url: string) => /^https?/.test(url) ? url : `${window.location.protocol}//${url}` diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index a5f8156..9b68213 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -2,6 +2,8 @@ import { createForm } from '@felte/solid' import { validator } from '@felte/validator-zod' import { useNavigate } from '@solidjs/router' import { + Accessor, + Component, For, Show, createEffect, @@ -29,6 +31,7 @@ import { } from '~/apis' import { Button, ConfigTitle } from '~/components' import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants' +import { isSingBox } from '~/helpers' import { locale, setLocale, useI18n } from '~/i18n' import { autoSwitchTheme, @@ -114,7 +117,9 @@ const configFormSchema = z.object({ 'mixed-port': z.number(), }) -const ConfigForm = () => { +const ConfigForm: Component<{ backendVersion: Accessor }> = ({ + backendVersion, +}) => { const [t] = useI18n() const navigate = useNavigate() @@ -196,109 +201,111 @@ const ConfigForm = () => { -
- - {(item) => ( -
- + + + + {(item) => ( +
+ - -
- )} -
- + +
+ )} +
+ -
-
- +
+
+ - - void updateBackendConfigAPI( - 'tun', - { enable: e.target.checked }, - refetch, - ) - } - /> + + void updateBackendConfigAPI( + 'tun', + { enable: e.target.checked }, + refetch, + ) + } + /> +
+ +
+ + + +
+ +
+ + + + void updateBackendConfigAPI( + 'tun', + { device: e.target.value }, + refetch, + ) + } + /> +
+ +
+ + + + void updateBackendConfigAPI( + 'interface-name', + e.target.value, + refetch, + ) + } + /> +
- -
- - - -
- -
- - - - void updateBackendConfigAPI( - 'tun', - { device: e.target.value }, - refetch, - ) - } - /> -
- -
- - - - void updateBackendConfigAPI( - 'interface-name', - e.target.value, - refetch, - ) - } - /> -
-
+
- + + +