Skip to content

Commit

Permalink
adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Nov 21, 2024
1 parent c338051 commit ec3efe8
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 85 deletions.
6 changes: 6 additions & 0 deletions scripts/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ const resolveMmdb = () =>
file: 'country.mmdb',
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb`
})
const resolveMetadb = () =>
resolveResource({
file: 'geoip.metadb',
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb`
})
const resolveGeosite = () =>
resolveResource({
file: 'geosite.dat',
Expand Down Expand Up @@ -351,6 +356,7 @@ const tasks = [
retry: 5
},
{ name: 'mmdb', func: resolveMmdb, retry: 5 },
{ name: 'metadb', func: resolveMetadb, retry: 5 },
{ name: 'geosite', func: resolveGeosite, retry: 5 },
{ name: 'geoip', func: resolveGeoIP, retry: 5 },
{ name: 'asn', func: resolveASN, retry: 5 },
Expand Down
3 changes: 2 additions & 1 deletion src/main/core/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async function prepareProfileWorkDir(current: string | undefined): Promise<void>
}
await Promise.all([
copy('country.mmdb'),
copy('geoip.metadb'),
copy('geoip.dat'),
copy('geosite.dat'),
copy('ASN.mmdb')
Expand Down Expand Up @@ -125,7 +126,7 @@ function runOverrideScript(
log('info', '脚本执行成功')
return newProfile
} catch (e) {
log('exception', `脚本执行失败: ${e}`)
log('exception', `脚本执行失败${e}`)
return profile
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/main/core/mihomoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export const mihomoUpdateProxyProviders = async (name: string): Promise<void> =>
return await instance.put(`/providers/proxies/${encodeURIComponent(name)}`)
}

export const mihomoRunProxyProviders = async (): Promise<IMihomoProxyProviders> => {
const runtime = await getRuntimeConfig()
return runtime?.['proxy-providers']
}

export const mihomoRuleProviders = async (): Promise<IMihomoRuleProviders> => {
const instance = await getAxios()
return await instance.get('/providers/rules')
Expand All @@ -129,11 +124,6 @@ export const mihomoUpdateRuleProviders = async (name: string): Promise<void> =>
return await instance.put(`/providers/rules/${encodeURIComponent(name)}`)
}

export const mihomoRunRuleProviders = async (): Promise<IMihomoRuleProviders> => {
const runtime = await getRuntimeConfig()
return runtime?.['rule-providers']
}

export const mihomoChangeProxy = async (group: string, proxy: string): Promise<IMihomoProxy> => {
const instance = await getAxios()
return await instance.put(`/proxies/${encodeURIComponent(group)}`, { name: proxy })
Expand Down Expand Up @@ -204,9 +194,9 @@ const mihomoTraffic = async (): Promise<void> => {
if (process.platform !== 'linux') {
tray?.setToolTip(
'↑' +
`${calcTraffic(json.up)}/s`.padStart(9) +
'\n↓' +
`${calcTraffic(json.down)}/s`.padStart(9)
`${calcTraffic(json.up)}/s`.padStart(9) +
'\n↓' +
`${calcTraffic(json.down)}/s`.padStart(9)
)
}
floatingWindow?.webContents.send('mihomoTraffic', json)
Expand Down
1 change: 1 addition & 0 deletions src/main/utils/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function initFiles(): Promise<void> {
}
await Promise.all([
copy('country.mmdb'),
copy('geoip.metadb'),
copy('geoip.dat'),
copy('geosite.dat'),
copy('ASN.mmdb')
Expand Down
4 changes: 0 additions & 4 deletions src/main/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
mihomoProxies,
mihomoProxyDelay,
mihomoProxyProviders,
mihomoRunProxyProviders,
mihomoRuleProviders,
mihomoRunRuleProviders,
mihomoRules,
mihomoUnfixedProxy,
mihomoUpdateProxyProviders,
Expand Down Expand Up @@ -119,12 +117,10 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('mihomoProxies', ipcErrorWrapper(mihomoProxies))
ipcMain.handle('mihomoGroups', ipcErrorWrapper(mihomoGroups))
ipcMain.handle('mihomoProxyProviders', ipcErrorWrapper(mihomoProxyProviders))
ipcMain.handle('mihomoRunProxyProviders', ipcErrorWrapper(mihomoRunProxyProviders))
ipcMain.handle('mihomoUpdateProxyProviders', (_e, name) =>
ipcErrorWrapper(mihomoUpdateProxyProviders)(name)
)
ipcMain.handle('mihomoRuleProviders', ipcErrorWrapper(mihomoRuleProviders))
ipcMain.handle('mihomoRunRuleProviders', ipcErrorWrapper(mihomoRunRuleProviders))
ipcMain.handle('mihomoUpdateRuleProviders', (_e, name) =>
ipcErrorWrapper(mihomoUpdateRuleProviders)(name)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
'geox-url': {
geoip: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat',
geosite: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat',
mmdb: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb',
mmdb: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb',
asn: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb'
}
}
Expand Down
49 changes: 35 additions & 14 deletions src/renderer/src/components/connections/connection-detail-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,41 @@ const CopyableSettingItem: React.FC<{
{ key: 'raw', text: displayName || (Array.isArray(value) ? value.join(', ') : value) },
...(Array.isArray(value) && value.length === prefix.length
? prefix.map((p, i) => value[i] ? ({
key: `${p},${value[i]}${suffix}`,
text: `${p},${value[i]}${suffix}`
key: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}`,
text: `${p},${p === 'IP-ASN' ? value[i].split(' ')[0] : value[i]}${suffix}`
}) : null).filter(Boolean)
: prefix.flatMap(p =>
(p === 'DOMAIN-SUFFIX'
? getSubDomains(Array.isArray(value) ? value[0] : value)
: p === 'IP-ASN'
? [(Array.isArray(value) ? value[0] : value).split(' ')[0]]
: [Array.isArray(value) ? value[0] : value]
).map(v => ({
key: `${p},${v}${suffix}`,
text: `${p},${v}${suffix}`
}))
))
(Array.isArray(value)
? value.map(v => p === 'DOMAIN-SUFFIX'
? getSubDomains(v).map(subV => ({
key: `${p},${subV}${suffix}`,
text: `${p},${subV}${suffix}`
}))
: p === 'IP-ASN' || p === 'SRC-IP-ASN'
? [{
key: `${p},${v.split(' ')[0]}${suffix}`,
text: `${p},${v.split(' ')[0]}${suffix}`
}]
: [{
key: `${p},${v}${suffix}`,
text: `${p},${v}${suffix}`
}]
).flat()
: p === 'DOMAIN-SUFFIX'
? getSubDomains(value).map(v => ({
key: `${p},${v}${suffix}`,
text: `${p},${v}${suffix}`
}))
: p === 'IP-ASN' || p === 'SRC-IP-ASN'
? [{
key: `${p},${value.split(' ')[0]}${suffix}`,
text: `${p},${value.split(' ')[0]}${suffix}`
}]
: [{
key: `${p},${value}${suffix}`,
text: `${p},${value}${suffix}`
}]
)))
]

return (
Expand Down Expand Up @@ -137,7 +158,7 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
suffix='/32'
/>
)}
{connection.metadata.sourceGeoIP && (
{connection.metadata.sourceGeoIP && connection.metadata.sourceGeoIP.length > 0 && (
<CopyableSettingItem
title='来源GeoIP'
value={connection.metadata.sourceGeoIP}
Expand All @@ -159,7 +180,7 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
suffix='/32'
/>
)}
{connection.metadata.destinationGeoIP && (
{connection.metadata.destinationGeoIP && connection.metadata.destinationGeoIP.length > 0 && (
<CopyableSettingItem
title='目标GeoIP'
value={connection.metadata.destinationGeoIP}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/resources/geo-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GeoData: React.FC = () => {
'geox-url': geoxUrl = {
geoip: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat',
geosite: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat',
mmdb: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb',
mmdb: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb',
asn: 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb'
},
'geodata-mode': geoMode = false,
Expand Down
48 changes: 32 additions & 16 deletions src/renderer/src/components/resources/proxy-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mihomoProxyProviders, mihomoUpdateProxyProviders, mihomoRunProxyProviders } from '@renderer/utils/ipc'
import {
mihomoProxyProviders,
mihomoUpdateProxyProviders,
getRuntimeConfig
} from '@renderer/utils/ipc'
import { Fragment, useEffect, useMemo, useState } from 'react'
import Viewer from './viewer'
import useSWR from 'swr'
Expand All @@ -7,6 +11,7 @@ import SettingItem from '../base/base-setting-item'
import { Button, Chip } from '@nextui-org/react'
import { IoMdRefresh, IoMdEye } from 'react-icons/io'
import { CgLoadbarDoc } from 'react-icons/cg'
import { MdEditDocument } from 'react-icons/md'
import dayjs from 'dayjs'
import { calcTraffic } from '@renderer/utils/calc'
import { getHash } from '@renderer/utils/hash'
Expand All @@ -19,8 +24,9 @@ const ProxyProvider: React.FC = () => {
useEffect(() => {
const fetchProviderPath = async (name: string) => {
try {
const providers = await mihomoRunProxyProviders()
const provider = providers[name]
const providers = await getRuntimeConfig()
const provider = providers['proxy-providers'][name]
console.log(provider)
if (provider?.path) {
setShowPath(provider.path)
} else if (provider?.url) {
Expand Down Expand Up @@ -73,7 +79,17 @@ const ProxyProvider: React.FC = () => {

return (
<SettingCard>
{ShowProvider && <Viewer onClose={() => { setShowProvider(false); setShowPath(''); setShowType('')}} path={ShowPath} type={ShowType} />}
{ShowProvider && (
<Viewer
onClose={() => {
setShowProvider(false)
setShowPath('')
setShowType('')
}}
path={ShowPath}
type={ShowType}
/>
)}
<SettingItem title="代理集合" divider>
<Button
size="sm"
Expand All @@ -100,33 +116,33 @@ const ProxyProvider: React.FC = () => {
>
<div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div>
<Button isIconOnly className="ml-2" size="sm">
<IoMdEye className="text-lg" />
</Button>
<Button
isIconOnly
className="ml-2"
size="sm"
onPress={() => {
onUpdate(provider.name, index)
setShowType(provider.vehicleType)
setShowPath(provider.name)
}}
>
<IoMdRefresh className={`text-lg ${updating[index] ? 'animate-spin' : ''}`} />
</Button>
<Button
isIconOnly
className="ml-2"
size="sm"
>
<IoMdEye className="text-lg" />
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
<Button
isIconOnly
className="ml-2"
size="sm"
onPress={() => {
setShowType(provider.vehicleType)
setShowPath(provider.name)
onUpdate(provider.name, index)
}}
>
<CgLoadbarDoc className="text-lg" />
<IoMdRefresh className={`text-lg ${updating[index] ? 'animate-spin' : ''}`} />
</Button>
</div>
</SettingItem>
Expand Down
57 changes: 36 additions & 21 deletions src/renderer/src/components/resources/rule-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mihomoRuleProviders, mihomoUpdateRuleProviders, mihomoRunRuleProviders } from '@renderer/utils/ipc'
import {
mihomoRuleProviders,
mihomoUpdateRuleProviders,
getRuntimeConfig
} from '@renderer/utils/ipc'
import { getHash } from '@renderer/utils/hash'
import Viewer from './viewer'
import { Fragment, useEffect, useMemo, useState } from 'react'
Expand All @@ -8,6 +12,7 @@ import SettingItem from '../base/base-setting-item'
import { Button, Chip } from '@nextui-org/react'
import { IoMdRefresh } from 'react-icons/io'
import { CgLoadbarDoc } from 'react-icons/cg'
import { MdEditDocument } from 'react-icons/md'
import dayjs from 'dayjs'

const RuleProvider: React.FC = () => {
Expand All @@ -27,8 +32,8 @@ const RuleProvider: React.FC = () => {
useEffect(() => {
const fetchProviderPath = async (name: string) => {
try {
const providers = await mihomoRunRuleProviders()
const provider = providers[name]
const providers = await getRuntimeConfig()
const provider = providers['rule-providers'][name]
if (provider?.path) {
setShowPath(provider.path)
} else if (provider?.url) {
Expand Down Expand Up @@ -68,12 +73,18 @@ const RuleProvider: React.FC = () => {

return (
<SettingCard>
{ShowProvider && <Viewer
path={ShowPath}
type={ShowType}
format={ShowFormat}
onClose={() => { setShowProvider(false); setShowPath(''); setShowType('') }}
/>}
{ShowProvider && (
<Viewer
path={ShowPath}
type={ShowType}
format={ShowFormat}
onClose={() => {
setShowProvider(false)
setShowPath('')
setShowType('')
}}
/>
)}
<SettingItem title="规则集合" divider>
<Button
size="sm"
Expand All @@ -99,17 +110,7 @@ const RuleProvider: React.FC = () => {
>
<div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div>
<Button
isIconOnly
className="ml-2"
size="sm"
onPress={() => {
onUpdate(provider.name, index)
}}
>
<IoMdRefresh className={`text-lg ${updating[index] ? 'animate-spin' : ''}`} />
</Button>
{provider.format !== "MrsRule" && (
{provider.format !== 'MrsRule' && (
<Button
isIconOnly
className="ml-2"
Expand All @@ -120,9 +121,23 @@ const RuleProvider: React.FC = () => {
setShowPath(provider.name)
}}
>
<CgLoadbarDoc className={`text-lg`} />
{provider.vehicleType == 'File' ? (
<MdEditDocument className={`text-lg`} />
) : (
<CgLoadbarDoc className={`text-lg`} />
)}
</Button>
)}
<Button
isIconOnly
className="ml-2"
size="sm"
onPress={() => {
onUpdate(provider.name, index)
}}
>
<IoMdRefresh className={`text-lg ${updating[index] ? 'animate-spin' : ''}`} />
</Button>
</div>
</SettingItem>
<SettingItem
Expand Down
Loading

0 comments on commit ec3efe8

Please sign in to comment.