Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Jan 2, 2025
1 parent d0a6d51 commit 8fe1f4f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
5 changes: 2 additions & 3 deletions src/main/config/controledMihomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
controledMihomoConfig.dns = controledMihomoConfig.dns || {}
controledMihomoConfig.dns['nameserver-policy'] = patch.dns['nameserver-policy']
}
controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
if (patch.hosts && patch.dns?.['use-hosts']) {
delete controledMihomoConfig.hosts
if (patch.dns?.['use-hosts']) {
controledMihomoConfig.hosts = patch.hosts
}
controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
if (!useNameserverPolicy) {
delete controledMihomoConfig?.dns?.['nameserver-policy']
}
Expand Down
58 changes: 37 additions & 21 deletions src/renderer/src/components/resources/proxy-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ProxyProvider: React.FC = () => {
if (showDetails.title) {
const fetchProviderPath = async (name: string): Promise<void> => {
try {
const providers= await getRuntimeConfig()
const providers = await getRuntimeConfig()
const provider = providers['proxy-providers'][name]
if (provider) {
setShowDetails((prev) => ({
Expand All @@ -48,6 +48,20 @@ const ProxyProvider: React.FC = () => {
const providers = useMemo(() => {
if (!data) return []
return Object.values(data.providers)
.map(provider => {
if (provider.vehicleType === 'Inline' || (provider.subscriptionInfo &&
provider.subscriptionInfo.Upload === 0 &&
provider.subscriptionInfo.Download === 0 &&
provider.subscriptionInfo.Total === 0 &&
provider.subscriptionInfo.Expire === 0)) {
return {
...provider,
subscriptionInfo: null
}
}
return provider
})

.filter(provider => 'subscriptionInfo' in provider)
.sort((a, b) => {
if (a.vehicleType === 'File' && b.vehicleType !== 'File') {
Expand Down Expand Up @@ -122,26 +136,28 @@ const ProxyProvider: React.FC = () => {
{/* <Button isIconOnly className="ml-2" size="sm">
<IoMdEye className="text-lg" />
</Button> */}
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
className="ml-2"
size="sm"
onPress={() => {
setShowDetails({
show: false,
path: provider.name,
type: provider.vehicleType,
title: provider.name
})
}}
>
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
{provider.vehicleType !== 'Inline' && (
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
className="ml-2"
size="sm"
onPress={() => {
setShowDetails({
show: false,
path: provider.name,
type: provider.vehicleType,
title: provider.name
})
}}
>
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
)}
<Button
isIconOnly
title="更新"
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/resources/rule-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const RuleProvider: React.FC = () => {
>
<div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div>
{provider.format !== 'MrsRule' && (
{provider.format !== 'MrsRule' && provider.vehicleType !== 'Inline' && (
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
Expand Down
16 changes: 8 additions & 8 deletions src/renderer/src/pages/dns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DNS: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { appConfig, patchAppConfig } = useAppConfig()
const { nameserverPolicy, useNameserverPolicy } = appConfig || {}
const { dns, hosts } = controledMihomoConfig || {}
const { dns } = controledMihomoConfig || {}
const {
ipv6 = false,
'fake-ip-range': fakeIPRange = '198.18.0.1/16',
Expand Down Expand Up @@ -54,7 +54,7 @@ const DNS: React.FC = () => {
domain,
value
})),
hosts: Object.entries(hosts || {}).map(([domain, value]) => ({ domain, value }))
hosts: useHosts ? [] : undefined
})

const setValues = (v: typeof values): void => {
Expand Down Expand Up @@ -140,7 +140,7 @@ const DNS: React.FC = () => {
className="app-nodrag"
color="primary"
onPress={() => {
const hostsObject = values.useHosts
const hostsObject = values.useHosts && values.hosts && values.hosts.length > 0
? Object.fromEntries(values.hosts.map(({ domain, value }) => [domain, value]))
: undefined
const dnsConfig = {
Expand Down Expand Up @@ -187,7 +187,7 @@ const DNS: React.FC = () => {
<Tab key="normal" title="取消映射" />
</Tabs>
</SettingItem>
{values.enhancedMode === 'fake-ip' ? (
{values.enhancedMode === 'fake-ip' && (
<>
<SettingItem title="回应范围" divider>
<Input
Expand All @@ -205,7 +205,7 @@ const DNS: React.FC = () => {
</div>
<Divider className="my-2" />
</>
) : null}
)}
<SettingItem title="IPv6" divider>
<Switch
size="sm"
Expand Down Expand Up @@ -320,14 +320,14 @@ const DNS: React.FC = () => {
size="sm"
isSelected={values.useHosts}
onValueChange={(v) => {
setValues({ ...values, useHosts: v })
setValues({ ...values, useHosts: v, hosts: v ? [] : undefined })
}}
/>
</SettingItem>
{values.useHosts && (
<div className="flex flex-col items-stretch">
<h3 className="mb-2"></h3>
{[...values.hosts, { domain: '', value: '' }].map(({ domain, value }, index) => (
{[...(values.hosts || []), { domain: '', value: '' }].map(({ domain, value }, index) => (
<div key={index} className="flex mb-2">
<div className="flex-[4]">
<Input
Expand All @@ -354,7 +354,7 @@ const DNS: React.FC = () => {
value={Array.isArray(value) ? value.join(',') : value}
onValueChange={(v) => handleSubkeyChange('hosts', domain, v, index)}
/>
{index < values.hosts.length && (
{index < (values.hosts || []).length && (
<Button
size="sm"
color="warning"
Expand Down

0 comments on commit 8fe1f4f

Please sign in to comment.