diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 10832388..a5bfbd93 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -238,8 +238,8 @@ async function downloadFile(url, path) { const resolveMmdb = () => resolveResource({ - file: 'country.mmdb', - downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb` + file: 'geoip.metadb', + downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb` }) const resolveGeosite = () => resolveResource({ diff --git a/src/main/core/mihomoApi.ts b/src/main/core/mihomoApi.ts index 7a7ca2d8..89d309da 100644 --- a/src/main/core/mihomoApi.ts +++ b/src/main/core/mihomoApi.ts @@ -114,11 +114,6 @@ export const mihomoUpdateProxyProviders = async (name: string): Promise => return await instance.put(`/providers/proxies/${encodeURIComponent(name)}`) } -export const mihomoRunProxyProviders = async (): Promise => { - const runtime = await getRuntimeConfig() - return runtime?.['proxy-providers'] -} - export const mihomoRuleProviders = async (): Promise => { const instance = await getAxios() return await instance.get('/providers/rules') @@ -129,11 +124,6 @@ export const mihomoUpdateRuleProviders = async (name: string): Promise => return await instance.put(`/providers/rules/${encodeURIComponent(name)}`) } -export const mihomoRunRuleProviders = async (): Promise => { - const runtime = await getRuntimeConfig() - return runtime?.['rule-providers'] -} - export const mihomoChangeProxy = async (group: string, proxy: string): Promise => { const instance = await getAxios() return await instance.put(`/proxies/${encodeURIComponent(group)}`, { name: proxy }) @@ -204,9 +194,9 @@ const mihomoTraffic = async (): Promise => { 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) diff --git a/src/main/utils/ipc.ts b/src/main/utils/ipc.ts index 48ab902c..c8021628 100644 --- a/src/main/utils/ipc.ts +++ b/src/main/utils/ipc.ts @@ -8,9 +8,7 @@ import { mihomoProxies, mihomoProxyDelay, mihomoProxyProviders, - mihomoRunProxyProviders, mihomoRuleProviders, - mihomoRunRuleProviders, mihomoRules, mihomoUnfixedProxy, mihomoUpdateProxyProviders, @@ -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) ) diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index 91e390f8..e2a0341d 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -107,7 +107,7 @@ export const defaultControledMihomoConfig: Partial = { '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' } } diff --git a/src/renderer/src/components/connections/connection-detail-modal.tsx b/src/renderer/src/components/connections/connection-detail-modal.tsx index a5674960..06887246 100644 --- a/src/renderer/src/components/connections/connection-detail-modal.tsx +++ b/src/renderer/src/components/connections/connection-detail-modal.tsx @@ -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 ( @@ -137,7 +158,7 @@ const ConnectionDetailModal: React.FC = (props) => { suffix='/32' /> )} - {connection.metadata.sourceGeoIP && ( + {connection.metadata.sourceGeoIP && connection.metadata.sourceGeoIP.length > 0 && ( = (props) => { suffix='/32' /> )} - {connection.metadata.destinationGeoIP && ( + {connection.metadata.destinationGeoIP && connection.metadata.destinationGeoIP.length > 0 && ( { '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, diff --git a/src/renderer/src/components/resources/proxy-provider.tsx b/src/renderer/src/components/resources/proxy-provider.tsx index da1d0a32..f58d4f2c 100644 --- a/src/renderer/src/components/resources/proxy-provider.tsx +++ b/src/renderer/src/components/resources/proxy-provider.tsx @@ -1,4 +1,8 @@ -import { mihomoProxyProviders, mihomoUpdateProxyProviders, mihomoRunProxyProviders } from '@renderer/utils/ipc' +import { + mihomoProxyProviders, + mihomoUpdateProxyProviders, + getRuntimeConfigStr +} from '@renderer/utils/ipc' import { Fragment, useEffect, useMemo, useState } from 'react' import Viewer from './viewer' import useSWR from 'swr' @@ -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' @@ -19,7 +24,7 @@ const ProxyProvider: React.FC = () => { useEffect(() => { const fetchProviderPath = async (name: string) => { try { - const providers = await mihomoRunProxyProviders() + const providers = await getRuntimeConfigStr()?.['rule-providers'] const provider = providers[name] if (provider?.path) { setShowPath(provider.path) @@ -73,7 +78,17 @@ const ProxyProvider: React.FC = () => { return ( - {ShowProvider && { setShowProvider(false); setShowPath(''); setShowType('')}} path={ShowPath} type={ShowType} />} + {ShowProvider && ( + { + setShowProvider(false) + setShowPath('') + setShowType('') + }} + path={ShowPath} + type={ShowType} + /> + )} - diff --git a/src/renderer/src/components/resources/rule-provider.tsx b/src/renderer/src/components/resources/rule-provider.tsx index 05d5e326..dc158279 100644 --- a/src/renderer/src/components/resources/rule-provider.tsx +++ b/src/renderer/src/components/resources/rule-provider.tsx @@ -1,4 +1,8 @@ -import { mihomoRuleProviders, mihomoUpdateRuleProviders, mihomoRunRuleProviders } from '@renderer/utils/ipc' +import { + mihomoRuleProviders, + mihomoUpdateRuleProviders, + getRuntimeConfigStr +} from '@renderer/utils/ipc' import { getHash } from '@renderer/utils/hash' import Viewer from './viewer' import { Fragment, useEffect, useMemo, useState } from 'react' @@ -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 = () => { @@ -27,7 +32,7 @@ const RuleProvider: React.FC = () => { useEffect(() => { const fetchProviderPath = async (name: string) => { try { - const providers = await mihomoRunRuleProviders() + const providers = await getRuntimeConfigStr()?.['rule-providers'] const provider = providers[name] if (provider?.path) { setShowPath(provider.path) @@ -68,12 +73,18 @@ const RuleProvider: React.FC = () => { return ( - {ShowProvider && { setShowProvider(false); setShowPath(''); setShowType('') }} - />} + {ShowProvider && ( + { + setShowProvider(false) + setShowPath('') + setShowType('') + }} + /> + )} - {provider.format !== "MrsRule" && ( + {provider.format !== 'MrsRule' && ( )} + { ) } -export async function mihomoRunProxyProviders(): Promise { - return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRunProxyProviders')) -} - export async function mihomoRuleProviders(): Promise { return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRuleProviders')) } @@ -57,10 +53,6 @@ export async function mihomoUpdateRuleProviders(name: string): Promise { ) } -export async function mihomoRunRuleProviders(): Promise { - return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRunRuleProviders')) -} - export async function mihomoChangeProxy(group: string, proxy: string): Promise { return ipcErrorWrapper( await window.electron.ipcRenderer.invoke('mihomoChangeProxy', group, proxy) diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index d7665139..08f8aed0 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -88,10 +88,10 @@ interface IMihomoConnectionDetail { network: 'tcp' | 'udp' type: string sourceIP: string - sourceGeoIP: string + sourceGeoIP: string[] sourceIPASN: string destinationIP: string - destinationGeoIP: string + destinationGeoIP: string[] destinationIPASN: string sourcePort: string destinationPort: string @@ -181,8 +181,6 @@ interface IMihomoRuleProvider { type: string updatedAt: string vehicleType: string - url: string - path: string } interface IMihomoProxyProviders { @@ -205,8 +203,6 @@ interface IMihomoProxyProvider { testUrl?: string updatedAt?: string vehicleType: string - url: string - path: string } interface ISysProxyConfig {