From ec3efe89c78bb687d52f367f881ffafdc88c6376 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Thu, 21 Nov 2024 20:17:21 +0800 Subject: [PATCH] adjust --- scripts/prepare.mjs | 6 ++ src/main/core/factory.ts | 3 +- src/main/core/mihomoApi.ts | 16 +----- src/main/utils/init.ts | 1 + src/main/utils/ipc.ts | 4 -- src/main/utils/template.ts | 2 +- .../connections/connection-detail-modal.tsx | 49 +++++++++++----- .../src/components/resources/geo-data.tsx | 2 +- .../components/resources/proxy-provider.tsx | 48 ++++++++++------ .../components/resources/rule-provider.tsx | 57 ++++++++++++------- src/renderer/src/utils/ipc.ts | 8 --- src/shared/types.d.ts | 8 +-- 12 files changed, 119 insertions(+), 85 deletions(-) diff --git a/scripts/prepare.mjs b/scripts/prepare.mjs index 10832388..fec61a9e 100644 --- a/scripts/prepare.mjs +++ b/scripts/prepare.mjs @@ -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', @@ -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 }, diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 75ce60ed..d5896c1b 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -56,6 +56,7 @@ async function prepareProfileWorkDir(current: string | undefined): Promise } await Promise.all([ copy('country.mmdb'), + copy('geoip.metadb'), copy('geoip.dat'), copy('geosite.dat'), copy('ASN.mmdb') @@ -125,7 +126,7 @@ function runOverrideScript( log('info', '脚本执行成功') return newProfile } catch (e) { - log('exception', `脚本执行失败: ${e}`) + log('exception', `脚本执行失败:${e}`) return profile } } 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/init.ts b/src/main/utils/init.ts index 5c3f8c4d..e0b9ae87 100644 --- a/src/main/utils/init.ts +++ b/src/main/utils/init.ts @@ -99,6 +99,7 @@ async function initFiles(): Promise { } await Promise.all([ copy('country.mmdb'), + copy('geoip.metadb'), copy('geoip.dat'), copy('geosite.dat'), copy('ASN.mmdb') 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..b66a2988 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, + getRuntimeConfig +} 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,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) { @@ -73,7 +79,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..e10e43b5 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, + getRuntimeConfig +} 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,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) { @@ -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 {