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 234cb5e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 65 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CopyableSettingItem: React.FC<{
: prefix.flatMap(p =>
(p === 'DOMAIN-SUFFIX'
? getSubDomains(Array.isArray(value) ? value[0] : value)
: p === 'IP-ASN'
: p === 'IP-ASN' || p === 'SRC-IP-ASN'
? [(Array.isArray(value) ? value[0] : value).split(' ')[0]]
: [Array.isArray(value) ? value[0] : value]
).map(v => ({
Expand Down
45 changes: 30 additions & 15 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,
getRuntimeConfigStr
} 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,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)
Expand Down Expand Up @@ -73,7 +78,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 +115,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
55 changes: 35 additions & 20 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,
getRuntimeConfigStr
} 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,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)
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
8 changes: 0 additions & 8 deletions src/renderer/src/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export async function mihomoUpdateProxyProviders(name: string): Promise<void> {
)
}

export async function mihomoRunProxyProviders(): Promise<IMihomoRuleProviders> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRunProxyProviders'))
}

export async function mihomoRuleProviders(): Promise<IMihomoRuleProviders> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRuleProviders'))
}
Expand All @@ -57,10 +53,6 @@ export async function mihomoUpdateRuleProviders(name: string): Promise<void> {
)
}

export async function mihomoRunRuleProviders(): Promise<IMihomoRuleProviders> {
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('mihomoRunRuleProviders'))
}

export async function mihomoChangeProxy(group: string, proxy: string): Promise<IMihomoProxy> {
return ipcErrorWrapper(
await window.electron.ipcRenderer.invoke('mihomoChangeProxy', group, proxy)
Expand Down
4 changes: 0 additions & 4 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ interface IMihomoRuleProvider {
type: string
updatedAt: string
vehicleType: string
url: string
path: string
}

interface IMihomoProxyProviders {
Expand All @@ -205,8 +203,6 @@ interface IMihomoProxyProvider {
testUrl?: string
updatedAt?: string
vehicleType: string
url: string
path: string
}

interface ISysProxyConfig {
Expand Down

0 comments on commit 234cb5e

Please sign in to comment.