fix: flickering issue of the config page under sing-box (#900)

This commit is contained in:
YetAnotherZephyruso 2024-08-10 01:33:12 +08:00 committed by GitHub
parent 41aa606572
commit b07647c549
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 19 deletions

View File

@ -41,7 +41,7 @@ export const ProxyPreviewBar = (props: {
return ( return (
<div class="flex items-center gap-2 py-2"> <div class="flex items-center gap-2 py-2">
<div class="my-2 flex flex-1 items-center justify-center overflow-hidden rounded-2xl [&>*]:h-2"> <div class="my-1 flex flex-1 items-center justify-center overflow-hidden rounded-2xl [&>*]:h-2">
<div <div
class="bg-success" class="bg-success"
style={{ style={{

View File

@ -1,7 +1,3 @@
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}`

View File

@ -5,7 +5,6 @@ import { toast } from 'solid-toast'
import { z } from 'zod' import { z } from 'zod'
import { import {
fetchBackendConfigAPI, fetchBackendConfigAPI,
fetchBackendVersionAPI,
flushFakeIPDataAPI, flushFakeIPDataAPI,
flushingFakeIPData, flushingFakeIPData,
isUpdateAvailableAPI, isUpdateAvailableAPI,
@ -23,7 +22,6 @@ 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,
@ -38,6 +36,11 @@ import {
useRequest, useRequest,
useTwemoji, useTwemoji,
} from '~/signals' } from '~/signals'
import {
backendVersion,
isSingBox,
updateBackendVersion,
} from '~/signals/version'
import type { DNSQuery } from '~/types' import type { DNSQuery } from '~/types'
const dnsQueryFormSchema = z.object({ const dnsQueryFormSchema = z.object({
@ -109,9 +112,7 @@ const configFormSchema = z.object({
'mixed-port': z.number(), 'mixed-port': z.number(),
}) })
const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({ const ConfigForm = () => {
backendVersion,
}) => {
const [t] = useI18n() const [t] = useI18n()
const portList = [ const portList = [
@ -192,7 +193,7 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
<option value={MODE_OPTIONS.Direct}>{t('direct')}</option> <option value={MODE_OPTIONS.Direct}>{t('direct')}</option>
</select> </select>
<Show when={!isSingBox(backendVersion())}> <Show when={!isSingBox()}>
<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) => (
@ -344,7 +345,7 @@ const ConfigForm: Component<{ backendVersion: Accessor<string> }> = ({
{t('restartCore')} {t('restartCore')}
</Button> </Button>
<Show when={!isSingBox(backendVersion())}> <Show when={!isSingBox()}>
<Button <Button
class="btn-secondary" class="btn-secondary"
loading={updatingGEODatabases()} loading={updatingGEODatabases()}
@ -527,15 +528,11 @@ export default () => {
const [t] = useI18n() const [t] = useI18n()
const [backendVersion, setBackendVersion] = createSignal('') updateBackendVersion()
onMount(async () => {
setBackendVersion(await fetchBackendVersionAPI())
})
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())}> <Show when={!isSingBox()}>
<ConfigTitle withDivider>{t('dnsQuery')}</ConfigTitle> <ConfigTitle withDivider>{t('dnsQuery')}</ConfigTitle>
<DNSQueryForm /> <DNSQueryForm />
@ -543,7 +540,7 @@ export default () => {
<ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle> <ConfigTitle withDivider>{t('coreConfig')}</ConfigTitle>
<ConfigForm backendVersion={backendVersion} /> <ConfigForm />
<ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle> <ConfigTitle withDivider>{t('xdConfig')}</ConfigTitle>

9
src/signals/version.ts Normal file
View File

@ -0,0 +1,9 @@
import { fetchBackendVersionAPI } from '~/apis'
export const [backendVersion, setBackendVersion] = createSignal('')
export const isSingBox = createMemo(() => {
return backendVersion().includes('sing-box')
})
export const updateBackendVersion = () => {
fetchBackendVersionAPI().then(setBackendVersion)
}