Skip to content

Commit

Permalink
adjust a little
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 7, 2024
1 parent 86ced8b commit fd884ec
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 138 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ out
.DS_Store
*.log*
.idea
.vscode
25 changes: 0 additions & 25 deletions src/main/core/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,6 @@ const buildContextMenu = (): Menu => {
}
},
{ type: 'separator' },
{
type: 'checkbox',
label: 'DNS',
checked: getControledMihomoConfig().dns?.enable ?? false,
click: (item): void => {
const enable = item.checked
setControledMihomoConfig({ dns: { enable } })
patchMihomoConfig({ dns: { enable } })
window?.webContents.send('controledMihomoConfigUpdated')
updateTrayMenu()
}
},
{
type: 'checkbox',
label: '域名嗅探',
checked: getControledMihomoConfig().sniffer?.enable ?? false,
click: (item): void => {
const enable = item.checked
setControledMihomoConfig({ sniffer: { enable } })
patchMihomoConfig({ sniffer: { enable } })
window?.webContents.send('controledMihomoConfigUpdated')
updateTrayMenu()
}
},
{ type: 'separator' },
{
type: 'submenu',
label: '打开目录',
Expand Down
10 changes: 2 additions & 8 deletions src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
'fake-ip-range': '198.18.0.1/16',
'use-hosts': false,
'use-system-hosts': false,
// 'respect-rules': false,
nameserver:[
'https://doh.pub/dns-query',
'https://dns.alidns.com/dns-query'
]
nameserver: ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query']
},
sniffer: {
enable: true,
Expand All @@ -58,9 +54,7 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
ports: [443]
}
},
"skip-domain": [
'+.push.apple.com'
]
'skip-domain': ['+.push.apple.com']
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/renderer/src/components/sider/dns-card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
import BorderSwitch from '@renderer/components/base/border-swtich'
import { MdOutlineDns } from "react-icons/md"
import { MdOutlineDns } from 'react-icons/md'
import { useLocation, useNavigate } from 'react-router-dom'
import { patchMihomoConfig } from '@renderer/utils/ipc'

Expand All @@ -20,7 +20,7 @@ const DNSCard: React.FC = () => {

return (
<Card
className={`w-[50%] ml-1 mb-2 ${match ? 'bg-primary' : ''}`}
className={`w-[50%] mr-1 mb-2 ${match ? 'bg-primary' : ''}`}
isPressable
onPress={() => navigate('/dns')}
>
Expand All @@ -45,9 +45,7 @@ const DNSCard: React.FC = () => {
</div>
</CardBody>
<CardFooter className="pt-1">
<h3
className={`select-none text-md font-bold ${match ? 'text-white' : 'text-foreground'}`}
>
<h3 className={`select-none text-md font-bold ${match ? 'text-white' : 'text-foreground'}`}>
DNS
</h3>
</CardFooter>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/sniff-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import BorderSwitch from '@renderer/components/base/border-swtich'
import { GrDomain } from "react-icons/gr"
import { GrDomain } from 'react-icons/gr'
import { useLocation, useNavigate } from 'react-router-dom'
import { patchMihomoConfig } from '@renderer/utils/ipc'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
Expand Down
98 changes: 47 additions & 51 deletions src/renderer/src/pages/dns.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Tab, Input, Switch, Tabs } from '@nextui-org/react'
import { Button, Tab, Input, Switch, Tabs, Divider } from '@nextui-org/react'
import BasePage from '@renderer/components/base/base-page'
import { MdDeleteForever } from 'react-icons/md'
import SettingCard from '@renderer/components/base/base-setting-card'
import SettingItem from '@renderer/components/base/base-setting-item'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
Expand All @@ -14,53 +15,48 @@ const DNS: React.FC = () => {
'enhanced-mode': enhancedMode = 'fake-ip',
'use-hosts': useHosts = false,
'use-system-hosts': useSystemHosts = false,
// 'respect-rules': respectRules = false,
nameserver =[
'https://doh.pub/dns-query',
'https://dns.alidns.com/dns-query'
],
nameserver = ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query']
} = dns || {}

const [values, setValues] = useState({
ipv6,
useHosts,
enhancedMode,
useSystemHosts,
// respectRules,
nameserver,
hosts: Object.entries(hosts || {}).map(([domain, value]) => ({ domain, value }))
})

const handleNameserverChange = (value: string, index: number) => {
const newNameservers = [...values.nameserver];
const handleNameserverChange = (value: string, index: number): void => {
const newNameservers = [...values.nameserver]
if (index === newNameservers.length) {
if (value.trim() !== '') {
newNameservers.push(value);
newNameservers.push(value)
}
} else {
if (value.trim() === '') {
newNameservers.splice(index, 1);
newNameservers.splice(index, 1)
} else {
newNameservers[index] = value;
newNameservers[index] = value
}
}
setValues({ ...values, nameserver: newNameservers });
setValues({ ...values, nameserver: newNameservers })
}
const handleHostsChange = (domain: string, value: string, index: number) => {
const newHosts = [...values.hosts];
const handleHostsChange = (domain: string, value: string, index: number): void => {
const newHosts = [...values.hosts]

if (index === newHosts.length) {
if (domain.trim() !== '' || value.trim() !== '') {
newHosts.push({ domain: domain.trim(), value: value.trim() });
newHosts.push({ domain: domain.trim(), value: value.trim() })
}
} else {
if (domain.trim() === '' && value.trim() === '') {
newHosts.splice(index, 1);
newHosts.splice(index, 1)
} else {
newHosts[index] = { domain: domain.trim(), value: value.trim() };
newHosts[index] = { domain: domain.trim(), value: value.trim() }
}
}
setValues({ ...values, hosts: newHosts });
setValues({ ...values, hosts: newHosts })
}

const onSave = async (patch: Partial<IMihomoConfig>): Promise<void> => {
Expand All @@ -78,26 +74,24 @@ const DNS: React.FC = () => {
onPress={() => {
const hostsObject = values.hosts.reduce((acc, { domain, value }) => {
if (domain) {
acc[domain] = value;
acc[domain] = value
}
return acc;
}, {});
return acc
}, {})
onSave({
dns: {
ipv6: values.ipv6,
'enhanced-mode': values.enhancedMode,
'use-hosts': values.useHosts,
'use-system-hosts': values.useSystemHosts,
// 'respect-rules': values.respectRules,
nameserver: values.nameserver,
nameserver: values.nameserver
},
hosts: hostsObject
})
}}
>
保存
</Button>

}
>
<SettingCard>
Expand All @@ -113,7 +107,7 @@ const DNS: React.FC = () => {
<Tab key="normal" title="取消映射" className="select-none" />
</Tabs>
</SettingItem>
<SettingItem title="IPV6" divider>
<SettingItem title="IPv6" divider>
<Switch
size="sm"
isSelected={values.ipv6}
Expand All @@ -122,33 +116,32 @@ const DNS: React.FC = () => {
}}
/>
</SettingItem>
{/* <SettingItem title="遵守路由规则连接" divider>
<Switch
size="sm"
isSelected={values.respectRules}
onValueChange={(v) => {
setValues({ ...values, respectRules: v })
}}
/>
</SettingItem> */}
<div className="flex flex-col items-stretch">
<h3 className="mb-2">DNS服务器</h3>
<h3 className="select-none mb-2">DNS服务器</h3>
{[...values.nameserver, ''].map((ns, index) => (
<div key={index} className="flex flex-row mb-2">
<div key={index} className="mb-2 flex">
<Input
fullWidth
size="sm"
placeholder="例: tls://223.5.5.5"
value={ns}
onChange={(e) => handleNameserverChange(e.target.value, index)}
className="flex-grow"
onValueChange={(v) => handleNameserverChange(v, index)}
/>
{index < values.nameserver.length && (
<Button size="sm" color="warning" onClick={() => handleNameserverChange('', index)}>-</Button>
<Button
className="ml-2"
size="sm"
variant="flat"
color="warning"
onClick={() => handleNameserverChange('', index)}
>
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
))}
</div>
<div style={{ borderBottom: '1px solid #dcdcdc', margin: '16px 0' }} />
<Divider />
<SettingItem title="使用系统hosts" divider>
<Switch
size="sm"
Expand All @@ -171,33 +164,36 @@ const DNS: React.FC = () => {
<div className="flex flex-col items-stretch">
<h3 className="mb-2"></h3>
{[...values.hosts, { domain: '', value: '' }].map(({ domain, value }, index) => (
<div key={index} className="flex w-full flex-wrap md:flex-nowrap gap-4">
<div className="flex-[4] mr-2">
<div key={index} className="flex mb-2">
<div className="flex-[4]">
<Input
size="sm"
fullWidth
placeholder="域名"
value={domain}
onChange={(e) => handleHostsChange(e.target.value, Array.isArray(value) ? value.join(', ') : value, index)}
className="w-full"
onValueChange={(v) =>
handleHostsChange(v, Array.isArray(value) ? value.join(', ') : value, index)
}
/>
</div>
<span className="mx-2">:</span>
<div className="flex-[6] flex items-center">
<span className="select-none mx-2">:</span>
<div className="flex-[6] flex">
<Input
size="sm"
fullWidth
placeholder="IP 或域名"
value={Array.isArray(value) ? value.join(', ') : value}
onChange={(e) => handleHostsChange(domain, e.target.value, index)}
className="flex-grow"
onValueChange={(v) => handleHostsChange(domain, v, index)}
/>
{index < values.hosts.length && (
<Button
size="sm"
color="warning"
className="ml-2 w-8 h-8 flex items-center justify-center"
variant="flat"
className="ml-2"
onClick={() => handleHostsChange('', '', index)}
>
-
<MdDeleteForever className="text-lg" />
</Button>
)}
</div>
Expand Down
Loading

0 comments on commit fd884ec

Please sign in to comment.