fix style
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run

This commit is contained in:
pompurin404 2024-09-03 15:34:16 +08:00
parent a1f477d502
commit c5ec08893e
No known key found for this signature in database
3 changed files with 84 additions and 62 deletions

View File

@ -18,8 +18,7 @@ const CollapseInput: React.FC<CollapseInputProps> = (props) => {
style={{ paddingInlineEnd: 0 }}
classNames={{
inputWrapper: 'cursor-pointer bg-transparent p-0 data-[hover=true]:bg-content2',
input: 'w-0 focus:w-[150px] transition-all duration-200',
innerWrapper: 'cursor-pointer p-0'
input: 'w-0 focus:w-[150px] focus:ml-2 transition-all duration-200'
}}
endContent={
<div

View File

@ -34,8 +34,8 @@ const DNS: React.FC = () => {
'https://dns.alidns.com/dns-query'
]
} = dns || {}
const [values, setValues] = useState({
const [changed, setChanged] = useState(false)
const [values, originSetValues] = useState({
ipv6,
useHosts,
enhancedMode,
@ -53,6 +53,11 @@ const DNS: React.FC = () => {
hosts: Object.entries(hosts || {}).map(([domain, value]) => ({ domain, value }))
})
const setValues = (v: typeof values): void => {
originSetValues(v)
setChanged(true)
}
const handleListChange = (type: string, value: string, index: number): void => {
const list = [...values[type]]
if (value.trim()) {
@ -112,48 +117,55 @@ const DNS: React.FC = () => {
),
useNameserverPolicy: values.useNameserverPolicy
})
await patchControledMihomoConfig(patch)
await restartCore()
try {
setChanged(false)
await patchControledMihomoConfig(patch)
await restartCore()
} catch (e) {
alert(e)
}
}
return (
<BasePage
title="DNS 设置"
header={
<Button
size="sm"
className="app-nodrag"
color="primary"
onPress={() => {
const hostsObject = Object.fromEntries(
values.hosts.map(({ domain, value }) => [domain, value])
)
const dnsConfig = {
ipv6: values.ipv6,
'fake-ip-range': values.fakeIPRange,
'fake-ip-filter': values.fakeIPFilter,
'enhanced-mode': values.enhancedMode,
'use-hosts': values.useHosts,
'use-system-hosts': values.useSystemHosts,
'respect-rules': values.respectRules,
nameserver: values.nameserver,
'proxy-server-nameserver': values.proxyServerNameserver,
fallback: [],
'fallback-filter': {}
}
if (values.useNameserverPolicy) {
dnsConfig['nameserver-policy'] = Object.fromEntries(
values.nameserverPolicy.map(({ domain, value }) => [domain, value])
changed && (
<Button
size="sm"
className="app-nodrag"
color="primary"
onPress={() => {
const hostsObject = Object.fromEntries(
values.hosts.map(({ domain, value }) => [domain, value])
)
}
onSave({
dns: dnsConfig,
hosts: hostsObject
})
}}
>
</Button>
const dnsConfig = {
ipv6: values.ipv6,
'fake-ip-range': values.fakeIPRange,
'fake-ip-filter': values.fakeIPFilter,
'enhanced-mode': values.enhancedMode,
'use-hosts': values.useHosts,
'use-system-hosts': values.useSystemHosts,
'respect-rules': values.respectRules,
nameserver: values.nameserver,
'proxy-server-nameserver': values.proxyServerNameserver,
fallback: [],
'fallback-filter': {}
}
if (values.useNameserverPolicy) {
dnsConfig['nameserver-policy'] = Object.fromEntries(
values.nameserverPolicy.map(({ domain, value }) => [domain, value])
)
}
onSave({
dns: dnsConfig,
hosts: hostsObject
})
}}
>
</Button>
)
}
>
<SettingCard>

View File

@ -22,8 +22,8 @@ const Sniffer: React.FC = () => {
'skip-domain': skipDomain = ['+.push.apple.com'],
'force-domain': forceDomain = []
} = sniffer || {}
const [values, setValues] = useState({
const [changed, setChanged] = useState(false)
const [values, originSetValues] = useState({
parsePureIP,
forceDNSMapping,
overrideDestination,
@ -31,10 +31,19 @@ const Sniffer: React.FC = () => {
skipDomain,
forceDomain
})
const setValues = (v: typeof values): void => {
originSetValues(v)
setChanged(true)
}
const onSave = async (patch: Partial<IMihomoConfig>): Promise<void> => {
await patchControledMihomoConfig(patch)
await restartCore()
try {
setChanged(false)
await patchControledMihomoConfig(patch)
await restartCore()
} catch (e) {
alert(e)
}
}
const handleSniffPortChange = (protocol: keyof typeof sniff, value: string): void => {
@ -69,25 +78,27 @@ const Sniffer: React.FC = () => {
<BasePage
title="域名嗅探设置"
header={
<Button
size="sm"
className="app-nodrag"
color="primary"
onPress={() =>
onSave({
sniffer: {
'parse-pure-ip': values.parsePureIP,
'force-dns-mapping': values.forceDNSMapping,
'override-destination': values.overrideDestination,
sniff: values.sniff,
'skip-domain': values.skipDomain,
'force-domain': values.forceDomain
}
})
}
>
</Button>
changed && (
<Button
size="sm"
className="app-nodrag"
color="primary"
onPress={() =>
onSave({
sniffer: {
'parse-pure-ip': values.parsePureIP,
'force-dns-mapping': values.forceDNSMapping,
'override-destination': values.overrideDestination,
sniff: values.sniff,
'skip-domain': values.skipDomain,
'force-domain': values.forceDomain
}
})
}
>
</Button>
)
}
>
<SettingCard>