Skip to content

Commit

Permalink
geo data config
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 8, 2024
1 parent afaeea2 commit f4b2a42
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 30 deletions.
12 changes: 9 additions & 3 deletions scripts/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.mmdb`
file: 'country.mmdb',
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb`
})
const resolveGeosite = () =>
resolveResource({
Expand All @@ -249,7 +249,12 @@ const resolveGeosite = () =>
const resolveGeoIP = () =>
resolveResource({
file: 'geoip.dat',
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat`
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat`
})
const resolveASN = () =>
resolveResource({
file: 'ASN.mmdb',
downloadURL: `https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb`
})
const resolveEnableLoopback = () =>
resolveResource({
Expand Down Expand Up @@ -285,6 +290,7 @@ const tasks = [
{ name: 'mmdb', func: resolveMmdb, retry: 5 },
{ name: 'geosite', func: resolveGeosite, retry: 5 },
{ name: 'geoip', func: resolveGeoIP, retry: 5 },
{ name: 'asn', func: resolveASN, retry: 5 },
{
name: 'font',
func: resolveFont,
Expand Down
7 changes: 7 additions & 0 deletions src/main/core/mihomoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export const mihomoChangeProxy = async (group: string, proxy: string): Promise<I
})) as IMihomoProxy
}

export const mihomoUpgradeGeo = async (): Promise<void> => {
const instance = await getAxios()
return instance.post('/configs/geo').catch((e) => {
return e.response.data
})
}

export const mihomoProxyDelay = async (proxy: string, url?: string): Promise<IMihomoDelay> => {
const appConfig = getAppConfig()
const { delayTestUrl, delayTestTimeout } = appConfig
Expand Down
2 changes: 1 addition & 1 deletion src/main/resolve/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function initConfig(): void {
}

function initFiles(): void {
const fileList = ['Country.mmdb', 'geoip.dat', 'geosite.dat']
const fileList = ['country.mmdb', 'geoip.dat', 'geosite.dat', 'ASN.mmdb']
for (const file of fileList) {
const targetPath = path.join(mihomoWorkDir(), file)
const testTargrtPath = path.join(mihomoTestDir(), file)
Expand Down
10 changes: 9 additions & 1 deletion src/main/utils/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
mihomoProxies,
mihomoProxyDelay,
mihomoRules,
mihomoUpgradeGeo,
mihomoVersion,
patchMihomoConfig,
startMihomoConnections,
Expand Down Expand Up @@ -34,6 +35,7 @@ import { triggerSysProxy } from '../resolve/sysproxy'
import { checkUpdate } from '../resolve/autoUpdater'
import { exePath, mihomoCorePath, mihomoWorkConfigPath } from './dirs'
import { execSync } from 'child_process'
import yaml from 'yaml'
import fs from 'fs'

export function registerIpcMainHandlers(): void {
Expand All @@ -43,6 +45,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('mihomoRules', mihomoRules)
ipcMain.handle('mihomoProxies', mihomoProxies)
ipcMain.handle('mihomoChangeProxy', (_e, group, proxy) => mihomoChangeProxy(group, proxy))
ipcMain.handle('mihomoUpgradeGeo', mihomoUpgradeGeo)
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) => mihomoProxyDelay(proxy, url))
ipcMain.handle('startMihomoLogs', startMihomoLogs)
ipcMain.handle('stopMihomoLogs', stopMihomoLogs)
Expand Down Expand Up @@ -71,6 +74,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
ipcMain.handle('getFilePath', getFilePath)
ipcMain.handle('readTextFile', (_e, filePath) => readTextFile(filePath))
ipcMain.handle('getRuntimeConfigStr', getRuntimeConfigStr)
ipcMain.handle('getRuntimeConfig', getRuntimeConfig)
ipcMain.handle('checkUpdate', () => checkUpdate())
ipcMain.handle('getVersion', () => app.getVersion())
Expand All @@ -91,10 +95,14 @@ function readTextFile(filePath: string): string {
return fs.readFileSync(filePath, 'utf8')
}

function getRuntimeConfig(): string {
function getRuntimeConfigStr(): string {
return fs.readFileSync(mihomoWorkConfigPath(), 'utf8')
}

function getRuntimeConfig(): Record<string, unknown> {
return yaml.parse(getRuntimeConfigStr())
}

async function setupFirewall(): Promise<void> {
return new Promise((resolve, reject) => {
const removeCommand = `
Expand Down
9 changes: 9 additions & 0 deletions src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
}
},
'skip-domain': ['+.push.apple.com']
},
'geo-auto-update': false,
'geo-update-interval': 24,
'geodata-mode': false,
'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',
asn: 'https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb'
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import SniffCard from '@renderer/components/sider/sniff-card'
import OverrideCard from '@renderer/components/sider/override-card'
import ConnCard from '@renderer/components/sider/conn-card'
import LogCard from '@renderer/components/sider/log-card'
import MihomoCoreCard from './components/sider/mihomo-core-card.tsx'
import TestCard from './components/sider/test-card.js'
import UpdaterButton from './components/updater/updater-button.js'
import MihomoCoreCard from '@renderer/components/sider/mihomo-core-card'
import ResourceCard from '@renderer/components/sider/resource-card'
import UpdaterButton from '@renderer/components/updater/updater-button'

const App: React.FC = () => {
const { setTheme } = useTheme()
Expand Down Expand Up @@ -63,9 +63,24 @@ const App: React.FC = () => {
/>
</div>
</div>

<div className="m-2">
<OutboundModeSwitcher />
</div>
{/* <div className="grid">
<SysproxySwitcher />
<TunSwitcher />
<ProfileCard />
<ProxyCard />
<MihomoCoreCard />
<ConnCard />
<DNSCard />
<SniffCard />
<LogCard />
<RuleCard />
<TestCard />
<OverrideCard />
</div> */}
<div className="flex justify-between mx-2 mb-2">
<SysproxySwitcher />
<TunSwitcher />
Expand All @@ -86,7 +101,7 @@ const App: React.FC = () => {
<RuleCard />
</div>
<div className="flex justify-between mx-2">
<TestCard />
<ResourceCard />
<OverrideCard />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/sider/config-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button } from
import React, { useEffect, useState } from 'react'
import MonacoEditor, { monaco } from 'react-monaco-editor'
import { useTheme } from 'next-themes'
import { getRuntimeConfig } from '@renderer/utils/ipc'
import { getRuntimeConfigStr } from '@renderer/utils/ipc'
interface Props {
onClose: () => void
}
Expand All @@ -23,7 +23,7 @@ const ConfigViewer: React.FC<Props> = (props) => {
}

const getContent = async (): Promise<void> => {
setCurrData(await getRuntimeConfig())
setCurrData(await getRuntimeConfigStr())
}

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/profile-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ProfileCard: React.FC = () => {
>
{info?.name}
</h3>
<div>
<div className="flex">
<Button
isIconOnly
size="sm"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Button, Card, CardBody, CardFooter } from '@nextui-org/react'
import React from 'react'
import { TbWorldCheck } from 'react-icons/tb'
import { FaLayerGroup } from 'react-icons/fa6'
import { useLocation, useNavigate } from 'react-router-dom'

const TestCard: React.FC = () => {
const ResourceCard: React.FC = () => {
const navigate = useNavigate()
const location = useLocation()
const match = location.pathname.includes('/tests')
const match = location.pathname.includes('/resources')

return (
<Card
className={`w-[50%] mr-1 mb-2 ${match ? 'bg-primary' : ''}`}
isPressable
onPress={() => navigate('/tests')}
onPress={() => navigate('/resources')}
>
<CardBody className="pb-1 pt-0 px-0">
<div className="flex justify-between">
Expand All @@ -22,7 +22,7 @@ const TestCard: React.FC = () => {
variant="flat"
color="default"
>
<TbWorldCheck
<FaLayerGroup
color="default"
className={`${match ? 'text-white' : 'text-foreground'} text-[24px] font-bold`}
/>
Expand All @@ -31,11 +31,11 @@ const TestCard: React.FC = () => {
</CardBody>
<CardFooter className="pt-1">
<h3 className={`select-none text-md font-bold ${match ? 'text-white' : 'text-foreground'}`}>
测试
外部资源
</h3>
</CardFooter>
</Card>
)
}

export default TestCard
export default ResourceCard
Loading

0 comments on commit f4b2a42

Please sign in to comment.