Skip to content

Commit

Permalink
keep hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Feb 9, 2025
1 parent 6f8ed50 commit 5fa776e
Show file tree
Hide file tree
Showing 9 changed files with 1,107 additions and 1,144 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"autoprefixer": "^10.4.20",
"cron-validator": "^1.3.1",
"driver.js": "^1.3.1",
"electron": "^33.1.0",
"electron": "^33.4.0",
"electron-builder": "25.0.4",
"electron-vite": "^2.3.0",
"electron-window-state": "^5.0.3",
Expand Down Expand Up @@ -88,7 +88,7 @@
"tsx": "^4.19.2",
"types-pac": "^1.0.3",
"typescript": "^5.6.3",
"vite": "^6.0.7",
"vite": "^6.1.0",
"vite-plugin-monaco-editor": "^1.1.0"
}
}
2,161 changes: 1,080 additions & 1,081 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/main/core/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ chokidar.watch(path.join(mihomoCoreDir(), 'meta-update'), {}).on('unlinkDir', as
})

export const mihomoIpcPath =
process.platform === 'win32' ? '\\\\.\\pipe\\MihomoParty\\mihomo' : '/tmp/mihomo-party.sock'
process.platform === 'win32' ? '\\\\.\\pipe\\Party\\mihomo' : '/tmp/party.sock'
const ctlParam = process.platform === 'win32' ? '-ext-ctl-pipe' : '-ext-ctl-unix'

let setPublicDNSTimer: NodeJS.Timeout | null = null
Expand All @@ -64,8 +64,6 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
diffWorkDir = false,
mihomoCpuPriority = 'PRIORITY_NORMAL',
disableLoopbackDetector = false,
disableEmbedCA = false,
disableSystemCA = false,
skipSafePathCheck = false
} = await getAppConfig()
const { 'log-level': logLevel } = await getControledMihomoConfig()
Expand Down Expand Up @@ -97,9 +95,8 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
const stdout = createWriteStream(logPath(), { flags: 'a' })
const stderr = createWriteStream(logPath(), { flags: 'a' })
const env = {
...process.env,
DISABLE_LOOPBACK_DETECTOR: String(disableLoopbackDetector),
DISABLE_EMBED_CA: String(disableEmbedCA),
DISABLE_SYSTEM_CA: String(disableSystemCA),
SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck)
}
child = spawn(
Expand Down
4 changes: 3 additions & 1 deletion src/main/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const defaultConfig: IAppConfig = {
controlDns: true,
controlSniff: true,
nameserverPolicy: {},
hosts: [],
siderOrder: [
'sysproxy',
'tun',
Expand All @@ -34,7 +35,8 @@ export const defaultConfig: IAppConfig = {
],
siderWidth: 250,
sysProxy: { enable: false, mode: 'manual' },
updateChannel: "release"
disableLoopbackDetector: false,
skipSafePathCheck: false
}

export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
Expand Down
21 changes: 3 additions & 18 deletions src/renderer/src/components/resources/proxy-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,10 @@ const ProxyProvider: React.FC = () => {
const providers = useMemo(() => {
if (!data) return []
return Object.values(data.providers)
.map(provider => {
if (provider.vehicleType === 'Inline' || provider.vehicleType === 'File') {
return {
...provider,
subscriptionInfo: null
}
}
return provider
})

.filter(provider => 'subscriptionInfo' in provider)
.filter((provider) => provider.vehicleType !== 'Compatible')
.sort((a, b) => {
if (a.vehicleType === 'File' && b.vehicleType !== 'File') {
return -1
}
if (a.vehicleType !== 'File' && b.vehicleType === 'File') {
return 1
}
return 0
const order = { File: 1, Inline: 2, HTTP: 3 }
return (order[a.vehicleType] || 4) - (order[b.vehicleType] || 4)
})
}, [data])
const [updating, setUpdating] = useState(Array(providers.length).fill(false))
Expand Down
13 changes: 4 additions & 9 deletions src/renderer/src/components/resources/rule-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const RuleProvider: React.FC = () => {
if (showDetails.title) {
const fetchProviderPath = async (name: string): Promise<void> => {
try {
const providers= await getRuntimeConfig()
const providers = await getRuntimeConfig()
const provider = providers['rule-providers'][name]
if (provider) {
setShowDetails((prev) => ({
Expand All @@ -49,13 +49,8 @@ const RuleProvider: React.FC = () => {
const providers = useMemo(() => {
if (!data) return []
return Object.values(data.providers).sort((a, b) => {
if (a.vehicleType === 'File' && b.vehicleType !== 'File') {
return -1
}
if (a.vehicleType !== 'File' && b.vehicleType === 'File') {
return 1
}
return 0
const order = { File: 1, Inline: 2, HTTP: 3 }
return (order[a.vehicleType] || 4) - (order[b.vehicleType] || 4)
})
}, [data])
const [updating, setUpdating] = useState(Array(providers.length).fill(false))
Expand Down Expand Up @@ -119,7 +114,7 @@ const RuleProvider: React.FC = () => {
>
<div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div>
{provider.format !== 'MrsRule' && (
{provider.format !== 'MrsRule' && provider.vehicleType !== 'Inline' && (
<Button
isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'}
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/src/pages/dns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { Key, ReactNode, useState } from 'react'
const DNS: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { appConfig, patchAppConfig } = useAppConfig()
const { nameserverPolicy, useNameserverPolicy } = appConfig || {}
const { hosts, nameserverPolicy, useNameserverPolicy } = appConfig || {}
const { dns } = controledMihomoConfig || {}
const {
ipv6 = false,
Expand Down Expand Up @@ -54,7 +54,7 @@ const DNS: React.FC = () => {
domain,
value
})),
hosts: useHosts ? [] : undefined
hosts: useHosts ? hosts : undefined
})

const setValues = (v: typeof values): void => {
Expand Down Expand Up @@ -119,7 +119,8 @@ const DNS: React.FC = () => {
nameserverPolicy: Object.fromEntries(
values.nameserverPolicy.map(({ domain, value }) => [domain, value])
),
useNameserverPolicy: values.useNameserverPolicy
useNameserverPolicy: values.useNameserverPolicy,
hosts: values.hosts
})
try {
setChanged(false)
Expand Down Expand Up @@ -320,7 +321,7 @@ const DNS: React.FC = () => {
size="sm"
isSelected={values.useHosts}
onValueChange={(v) => {
setValues({ ...values, useHosts: v, hosts: v ? [] : undefined })
setValues({ ...values, useHosts: v })
}}
/>
</SettingItem>
Expand Down
23 changes: 2 additions & 21 deletions src/renderer/src/pages/mihomo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ const Mihomo: React.FC = () => {
maxLogDays = 7,
sysProxy,
disableLoopbackDetector,
disableEmbedCA,
disableSystemCA,
skipSafePathCheck } = appConfig || {}
skipSafePathCheck
} = appConfig || {}
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const {
ipv6,
Expand Down Expand Up @@ -663,24 +662,6 @@ const Mihomo: React.FC = () => {
}}
/>
</SettingItem>
<SettingItem title="不使用内置 CA 证书" divider>
<Switch
size="sm"
isSelected={disableEmbedCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableEmbedCA', v)
}}
/>
</SettingItem>
<SettingItem title="不使用系统 CA 证书" divider>
<Switch
size="sm"
isSelected={disableSystemCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableSystemCA', v)
}}
/>
</SettingItem>
<SettingItem title="日志保留天数" divider>
<Input
size="sm"
Expand Down
9 changes: 6 additions & 3 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,14 @@ interface ISysProxyConfig {
pacScript?: string
}

interface IHost {
domain: string
value: string | string[]
}

interface IAppConfig {
core: 'mihomo' | 'mihomo-alpha'
disableLoopbackDetector: boolean
disableEmbedCA: boolean
disableSystemCA: boolean
skipSafePathCheck: boolean
proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name'
Expand Down Expand Up @@ -308,7 +311,6 @@ interface IAppConfig {
appTheme: AppTheme
customTheme?: string
autoCheckUpdate: boolean
updateChannel: string
silentStart: boolean
autoCloseConnection: boolean
sysProxy: ISysProxyConfig
Expand All @@ -328,6 +330,7 @@ interface IAppConfig {
webdavPassword?: string
useNameserverPolicy: boolean
nameserverPolicy: { [key: string]: string | string[] }
hosts: IHost[]
showWindowShortcut?: string
showFloatingWindowShortcut?: string
triggerSysProxyShortcut?: string
Expand Down

0 comments on commit 5fa776e

Please sign in to comment.