Compare commits

...

3 Commits

Author SHA1 Message Date
ezequielnick
f7b9eb2113 refactor: rewrite DNS control module with override logic 2025-08-04 13:20:24 +08:00
ezequielnick
d8aeb63584 feat: optimize and improve subscription switching 2025-08-04 13:17:43 +08:00
ezequielnick
f153217372 chore: Upgrade tailwindcss 2025-08-04 09:18:58 +08:00
34 changed files with 811 additions and 741 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ out
*.log* *.log*
.idea .idea
*.ttf *.ttf
party.md

View File

@ -54,8 +54,9 @@ pkg:
file: build/background.png file: build/background.png
linux: linux:
desktop: desktop:
Name: Mihomo Party entry:
MimeType: 'x-scheme-handler/clash;x-scheme-handler/mihomo' Name: Mihomo Party
MimeType: 'x-scheme-handler/clash;x-scheme-handler/mihomo'
target: target:
- deb - deb
- rpm - rpm

View File

@ -1,6 +1,7 @@
import { resolve } from 'path' import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite' import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// https://github.com/vdesjs/vite-plugin-monaco-editor/issues/21#issuecomment-1827562674 // https://github.com/vdesjs/vite-plugin-monaco-editor/issues/21#issuecomment-1827562674
import monacoEditorPluginModule from 'vite-plugin-monaco-editor' import monacoEditorPluginModule from 'vite-plugin-monaco-editor'
const isObjectWithDefaultFunction = ( const isObjectWithDefaultFunction = (
@ -37,6 +38,7 @@ export default defineConfig({
}, },
plugins: [ plugins: [
react(), react(),
tailwindcss(),
monacoEditorPlugin({ monacoEditorPlugin({
languageWorkers: ['editorWorkerService', 'typescript', 'css'], languageWorkers: ['editorWorkerService', 'typescript', 'css'],
customDistPath: (_, out) => `${out}/monacoeditorwork`, customDistPath: (_, out) => `${out}/monacoeditorwork`,

View File

@ -51,6 +51,7 @@
"@electron-toolkit/eslint-config-prettier": "^3.0.0", "@electron-toolkit/eslint-config-prettier": "^3.0.0",
"@electron-toolkit/eslint-config-ts": "^3.1.0", "@electron-toolkit/eslint-config-ts": "^3.1.0",
"@electron-toolkit/tsconfig": "^1.0.1", "@electron-toolkit/tsconfig": "^1.0.1",
"@tailwindcss/vite": "^4.1.11",
"@types/adm-zip": "^0.5.7", "@types/adm-zip": "^0.5.7",
"@types/express": "^5.0.3", "@types/express": "^5.0.3",
"@types/node": "^24.1.0", "@types/node": "^24.1.0",
@ -59,7 +60,6 @@
"@types/react-dom": "^19.1.7", "@types/react-dom": "^19.1.7",
"@types/ws": "^8.18.1", "@types/ws": "^8.18.1",
"@vitejs/plugin-react": "^4.7.0", "@vitejs/plugin-react": "^4.7.0",
"autoprefixer": "^10.4.21",
"cron-validator": "^1.4.0", "cron-validator": "^1.4.0",
"driver.js": "^1.3.6", "driver.js": "^1.3.6",
"electron": "^37.2.5", "electron": "^37.2.5",
@ -87,7 +87,7 @@
"react-router-dom": "^7.7.1", "react-router-dom": "^7.7.1",
"react-virtuoso": "^4.13.0", "react-virtuoso": "^4.13.0",
"swr": "^2.3.4", "swr": "^2.3.4",
"tailwindcss": "^3.4.17", "tailwindcss": "^4.1.11",
"tar": "^7.4.3", "tar": "^7.4.3",
"tsx": "^4.20.3", "tsx": "^4.20.3",
"types-pac": "^1.0.3", "types-pac": "^1.0.3",

1230
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +0,0 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
}

View File

@ -20,15 +20,22 @@ export async function getControledMihomoConfig(force = false): Promise<Partial<I
export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> { export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>): Promise<void> {
const { useNameserverPolicy, controlDns = true, controlSniff = true } = await getAppConfig() const { useNameserverPolicy, controlDns = true, controlSniff = true } = await getAppConfig()
if (!controlDns) {
// DNS 配置覆写逻辑
if (controlDns) {
if (!controledMihomoConfig.dns || controledMihomoConfig.dns?.ipv6 === undefined) {
controledMihomoConfig.dns = { ...defaultControledMihomoConfig.dns }
}
const originalEnable = controledMihomoConfig.dns?.enable
controledMihomoConfig.dns = deepMerge(controledMihomoConfig.dns || {}, defaultControledMihomoConfig.dns || {})
if (originalEnable !== undefined) {
controledMihomoConfig.dns.enable = originalEnable
}
} else {
delete controledMihomoConfig.dns delete controledMihomoConfig.dns
delete controledMihomoConfig.hosts delete controledMihomoConfig.hosts
} else {
// 从不接管状态恢复
if (controledMihomoConfig.dns?.ipv6 === undefined) {
controledMihomoConfig.dns = defaultControledMihomoConfig.dns
}
} }
if (!controlSniff) { if (!controlSniff) {
delete controledMihomoConfig.sniffer delete controledMihomoConfig.sniffer
} else { } else {
@ -37,6 +44,7 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
controledMihomoConfig.sniffer = defaultControledMihomoConfig.sniffer controledMihomoConfig.sniffer = defaultControledMihomoConfig.sniffer
} }
} }
if (patch.hosts) { if (patch.hosts) {
controledMihomoConfig.hosts = patch.hosts controledMihomoConfig.hosts = patch.hosts
} }
@ -44,7 +52,9 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
controledMihomoConfig.dns = controledMihomoConfig.dns || {} controledMihomoConfig.dns = controledMihomoConfig.dns || {}
controledMihomoConfig.dns['nameserver-policy'] = patch.dns['nameserver-policy'] controledMihomoConfig.dns['nameserver-policy'] = patch.dns['nameserver-policy']
} }
controledMihomoConfig = deepMerge(controledMihomoConfig, patch) controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
if (!useNameserverPolicy) { if (!useNameserverPolicy) {
delete controledMihomoConfig?.dns?.['nameserver-policy'] delete controledMihomoConfig?.dns?.['nameserver-policy']
} }

View File

@ -37,15 +37,21 @@ export async function getProfileItem(id: string | undefined): Promise<IProfileIt
export async function changeCurrentProfile(id: string): Promise<void> { export async function changeCurrentProfile(id: string): Promise<void> {
const config = await getProfileConfig() const config = await getProfileConfig()
const current = config.current const current = config.current
if (current === id) {
return
}
config.current = id config.current = id
await setProfileConfig(config) await setProfileConfig(config)
try { try {
await restartCore() await restartCore()
} catch (e) { } catch (e) {
// 如果重启失败,恢复原来的配置
config.current = current config.current = current
throw e
} finally {
await setProfileConfig(config) await setProfileConfig(config)
throw e
} }
} }

View File

@ -212,7 +212,12 @@ export async function restartCore(): Promise<void> {
try { try {
await startCore() await startCore()
} catch (e) { } catch (e) {
dialog.showErrorBox(i18next.t('mihomo.error.coreStartFailed'), `${e}`) // 记录错误到日志而不是显示阻塞对话框
await writeFile(logPath(), `[Manager]: restart core failed, ${e}\n`, {
flag: 'a'
})
// 重新抛出错误,让调用者处理
throw e
} }
} }

View File

@ -79,8 +79,10 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
'fake-ip-filter': ['*', '+.lan', '+.local', 'time.*.com', 'ntp.*.com', '+.market.xiaomi.com'], 'fake-ip-filter': ['*', '+.lan', '+.local', 'time.*.com', 'ntp.*.com', '+.market.xiaomi.com'],
'use-hosts': false, 'use-hosts': false,
'use-system-hosts': false, 'use-system-hosts': false,
nameserver: ['https://120.53.53.53/dns-query', 'https://223.5.5.5/dns-query'], 'respect-rules': false,
'proxy-server-nameserver': ['https://120.53.53.53/dns-query', 'https://223.5.5.5/dns-query'], 'default-nameserver': ['tls://223.5.5.5'],
nameserver: ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query'],
'proxy-server-nameserver': ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query'],
'direct-nameserver': [] 'direct-nameserver': []
}, },
sniffer: { sniffer: {

View File

@ -373,13 +373,13 @@ const App: React.FC = () => {
setSiderWidthValue(e.clientX) setSiderWidthValue(e.clientX)
} }
}} }}
className={`w-full h-[100vh] flex ${resizing ? 'cursor-ew-resize' : ''}`} className={`w-full h-screen flex ${resizing ? 'cursor-ew-resize' : ''}`}
> >
{siderWidthValue === narrowWidth ? ( {siderWidthValue === narrowWidth ? (
<div style={{ width: `${narrowWidth}px` }} className="side h-full"> <div style={{ width: `${narrowWidth}px` }} className="side h-full">
<div className="app-drag flex justify-center items-center z-40 bg-transparent h-[49px]"> <div className="app-drag flex justify-center items-center z-40 bg-transparent h-[49px]">
{platform !== 'darwin' && ( {platform !== 'darwin' && (
<MihomoIcon className="h-[32px] leading-[32px] text-lg mx-[1px]" /> <MihomoIcon className="h-[32px] leading-[32px] text-lg mx-px" />
)} )}
<UpdaterButton iconOnly={true} /> <UpdaterButton iconOnly={true} />
</div> </div>
@ -417,7 +417,7 @@ const App: React.FC = () => {
className={`flex justify-between p-2 ${!useWindowFrame && platform === 'darwin' ? 'ml-[60px]' : ''}`} className={`flex justify-between p-2 ${!useWindowFrame && platform === 'darwin' ? 'ml-[60px]' : ''}`}
> >
<div className="flex ml-1"> <div className="flex ml-1">
<MihomoIcon className="h-[32px] leading-[32px] text-lg mx-[1px]" /> <MihomoIcon className="h-[32px] leading-[32px] text-lg mx-px" />
<h3 className="text-lg font-bold leading-[32px]">ihomo Party</h3> <h3 className="text-lg font-bold leading-[32px]">ihomo Party</h3>
</div> </div>
<UpdaterButton /> <UpdaterButton />

View File

@ -59,9 +59,9 @@ const FloatingApp: React.FC = () => {
}, []) }, [])
return ( return (
<div className="app-drag h-[100vh] w-[100vw] overflow-hidden"> <div className="app-drag h-screen w-screen overflow-hidden">
<div className="floating-bg border-1 border-divider flex rounded-full bg-content1 h-[calc(100%-2px)] w-[calc(100%-2px)]"> <div className="floating-bg border border-divider flex rounded-full bg-content1 h-[calc(100%-2px)] w-[calc(100%-2px)]">
<div className="flex justify-center items-center h-[100%] aspect-square"> <div className="flex justify-center items-center h-full aspect-square">
<div <div
onContextMenu={(e) => { onContextMenu={(e) => {
e.preventDefault() e.preventDefault()

View File

@ -1,6 +1,8 @@
@tailwind base; @import 'tailwindcss';
@tailwind components; @plugin './hero.ts';
@tailwind utilities;
@source '../**/*.{js,ts,jsx,tsx}';
@source '../../../../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}';
.floating-text { .floating-text {
font-family: font-family:

View File

@ -0,0 +1,2 @@
import { heroui } from '@heroui/react'
export default heroui()

View File

@ -1,6 +1,12 @@
@tailwind base; @import 'tailwindcss';
@tailwind components; @plugin './hero.ts';
@tailwind utilities;
@source '../**/*.{js,ts,jsx,tsx}';
@source '../../../../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}';
@theme {
--default-font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
@font-face { @font-face {
font-family: 'Noto Color Emoji'; font-family: 'Noto Color Emoji';

View File

@ -39,7 +39,7 @@ const ConnectionItem: React.FC<Props> = (props) => {
<Chip <Chip
color={`${info.isActive ? 'primary' : 'danger'}`} color={`${info.isActive ? 'primary' : 'danger'}`}
size="sm" size="sm"
radius="sm" radius="xs"
variant="dot" variant="dot"
> >
{info.metadata.type}({info.metadata.network.toUpperCase()}) {info.metadata.type}({info.metadata.network.toUpperCase()})
@ -65,16 +65,16 @@ const ConnectionItem: React.FC<Props> = (props) => {
<Chip <Chip
className="flag-emoji text-ellipsis whitespace-nowrap overflow-hidden" className="flag-emoji text-ellipsis whitespace-nowrap overflow-hidden"
size="sm" size="sm"
radius="sm" radius="xs"
variant="bordered" variant="bordered"
> >
{info.chains[0]} {info.chains[0]}
</Chip> </Chip>
<Chip size="sm" radius="sm" variant="bordered"> <Chip size="sm" radius="xs" variant="bordered">
{calcTraffic(info.upload)} {calcTraffic(info.download)} {calcTraffic(info.upload)} {calcTraffic(info.download)}
</Chip> </Chip>
{info.uploadSpeed !== 0 || info.downloadSpeed !== 0 ? ( {info.uploadSpeed !== 0 || info.downloadSpeed !== 0 ? (
<Chip color="primary" size="sm" radius="sm" variant="bordered"> <Chip color="primary" size="sm" radius="xs" variant="bordered">
{calcTraffic(info.uploadSpeed || 0)}/s {calcTraffic(info.downloadSpeed || 0)} {calcTraffic(info.uploadSpeed || 0)}/s {calcTraffic(info.downloadSpeed || 0)}
/s /s
</Chip> </Chip>

View File

@ -14,7 +14,7 @@ import {
import { calcPercent, calcTraffic } from '@renderer/utils/calc' import { calcPercent, calcTraffic } from '@renderer/utils/calc'
import { IoMdMore, IoMdRefresh } from 'react-icons/io' import { IoMdMore, IoMdRefresh } from 'react-icons/io'
import dayjs from '@renderer/utils/dayjs' import dayjs from '@renderer/utils/dayjs'
import React, { Key, useEffect, useMemo, useState } from 'react' import React, { Key, useMemo, useState } from 'react'
import EditFileModal from './edit-file-modal' import EditFileModal from './edit-file-modal'
import EditInfoModal from './edit-info-modal' import EditInfoModal from './edit-info-modal'
import { useSortable } from '@dnd-kit/sortable' import { useSortable } from '@dnd-kit/sortable'
@ -72,7 +72,8 @@ const ProfileItem: React.FC<Props> = (props) => {
id: info.id id: info.id
}) })
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null
const [disableSelect, setDisableSelect] = useState(false) const [isActuallyDragging, setIsActuallyDragging] = useState(false)
const [clickStartPos, setClickStartPos] = useState<{ x: number; y: number } | null>(null)
const menuItems: MenuItem[] = useMemo(() => { const menuItems: MenuItem[] = useMemo(() => {
const list = [ const list = [
@ -150,19 +151,35 @@ const ProfileItem: React.FC<Props> = (props) => {
setDropdownOpen(true) setDropdownOpen(true)
} }
useEffect(() => { // 智能区分点击和拖拽的事件处理
if (isDragging) { const handleMouseDown = (e: React.MouseEvent) => {
setTimeout(() => { setClickStartPos({ x: e.clientX, y: e.clientY })
setDisableSelect(true) setIsActuallyDragging(false)
}, 200) }
} else {
setTimeout(() => { const handleMouseMove = (e: React.MouseEvent) => {
setDisableSelect(false) if (clickStartPos) {
}, 200) const dx = e.clientX - clickStartPos.x
const dy = e.clientY - clickStartPos.y
// 移动距离超过 5px 认为是拖拽
if (dx * dx + dy * dy > 25) {
setIsActuallyDragging(true)
}
} }
}, [isDragging]) }
const handleMouseUp = () => {
// 如果没有拖拽,则处理为点击事件
if (!isActuallyDragging && !isDragging && clickStartPos) {
setSelecting(true)
onPress().finally(() => {
setSelecting(false)
})
}
setClickStartPos(null)
setTimeout(() => setIsActuallyDragging(false), 100)
}
return ( return (
<div <div
@ -186,18 +203,19 @@ const ProfileItem: React.FC<Props> = (props) => {
<Card <Card
as="div" as="div"
fullWidth fullWidth
isPressable isPressable={false}
onPress={() => {
if (disableSelect) return
setSelecting(true)
onPress().finally(() => {
setSelecting(false)
})
}}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
className={`${isCurrent ? 'bg-primary' : ''} ${selecting ? 'blur-sm' : ''}`} className={`${isCurrent ? 'bg-primary' : ''} ${selecting ? 'blur-sm' : ''} cursor-pointer`}
> >
<div ref={setNodeRef} {...attributes} {...listeners} className="w-full h-full"> <div
ref={setNodeRef}
{...attributes}
{...listeners}
className="w-full h-full"
onMouseDownCapture={handleMouseDown}
onMouseMoveCapture={handleMouseMove}
onMouseUpCapture={handleMouseUp}
>
<CardBody className="pb-1"> <CardBody className="pb-1">
<div className="flex justify-between h-[32px]"> <div className="flex justify-between h-[32px]">
<h3 <h3

View File

@ -60,7 +60,7 @@ const ProxyItem: React.FC<Props> = (props) => {
onPress={() => onSelect(group.name, proxy.name)} onPress={() => onSelect(group.name, proxy.name)}
isPressable isPressable
fullWidth fullWidth
shadow="sm" shadow="xs"
className={`${ className={`${
fixed fixed
? 'bg-secondary/30 border-r-2 border-r-secondary border-l-2 border-l-secondary' ? 'bg-secondary/30 border-r-2 border-r-secondary border-l-2 border-l-secondary'
@ -68,7 +68,7 @@ const ProxyItem: React.FC<Props> = (props) => {
? 'bg-primary/30 border-r-2 border-r-primary border-l-2 border-l-primary' ? 'bg-primary/30 border-r-2 border-r-primary border-l-2 border-l-primary'
: 'bg-content2' : 'bg-content2'
}`} }`}
radius="sm" radius="xs"
> >
<CardBody className="p-1"> <CardBody className="p-1">
{proxyDisplayMode === 'full' ? ( {proxyDisplayMode === 'full' ? (

View File

@ -3,7 +3,7 @@ import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-c
import BorderSwitch from '@renderer/components/base/border-swtich' import BorderSwitch from '@renderer/components/base/border-swtich'
import { LuServer } from 'react-icons/lu' import { LuServer } from 'react-icons/lu'
import { useLocation, useNavigate } from 'react-router-dom' import { useLocation, useNavigate } from 'react-router-dom'
import { patchMihomoConfig } from '@renderer/utils/ipc' import { restartCore } from '@renderer/utils/ipc'
import { useSortable } from '@dnd-kit/sortable' import { useSortable } from '@dnd-kit/sortable'
import { CSS } from '@dnd-kit/utilities' import { CSS } from '@dnd-kit/utilities'
import { useAppConfig } from '@renderer/hooks/use-app-config' import { useAppConfig } from '@renderer/hooks/use-app-config'
@ -15,15 +15,14 @@ interface Props {
} }
const DNSCard: React.FC<Props> = (props) => { const DNSCard: React.FC<Props> = (props) => {
const { t } = useTranslation() const { t } = useTranslation()
const { appConfig } = useAppConfig() const { appConfig, patchAppConfig } = useAppConfig()
const { iconOnly } = props const { iconOnly } = props
const { dnsCardStatus = 'col-span-1', controlDns = true } = appConfig || {} const { dnsCardStatus = 'col-span-1', controlDns = true } = appConfig || {}
const location = useLocation() const location = useLocation()
const navigate = useNavigate() const navigate = useNavigate()
const match = location.pathname.includes('/dns') const match = location.pathname.includes('/dns')
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { dns, tun } = controledMihomoConfig || {} const { tun } = controledMihomoConfig || {}
const { enable = true } = dns || {}
const { const {
attributes, attributes,
listeners, listeners,
@ -35,20 +34,33 @@ const DNSCard: React.FC<Props> = (props) => {
id: 'dns' id: 'dns'
}) })
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null
const onChange = async (enable: boolean): Promise<void> => { const onChange = async (controlDnsEnabled: boolean): Promise<void> => {
await patchControledMihomoConfig({ dns: { enable } }) try {
await patchMihomoConfig({ dns: { enable } }) await patchAppConfig({ controlDns: controlDnsEnabled })
await patchControledMihomoConfig({})
await restartCore()
} catch (e) {
alert(e)
}
} }
if (iconOnly) { if (iconOnly) {
return ( return (
<div className={`${dnsCardStatus} ${!controlDns ? 'hidden' : ''} flex justify-center`}> <div className={`${dnsCardStatus} flex justify-center`}>
<Tooltip content={t('sider.cards.dns')} placement="right"> <Tooltip
content={
controlDns
? `${t('sider.cards.dns')} (${t('sider.cards.dns.overrideMode')})`
: `${t('sider.cards.dns')} (${t('sider.cards.dns.originalConfig')})`
}
placement="right"
>
<Button <Button
size="sm" size="sm"
isIconOnly isIconOnly
color={match ? 'primary' : 'default'} color={match ? 'primary' : 'default'}
variant={match ? 'solid' : 'light'} variant={match ? 'solid' : 'light'}
className={!controlDns ? 'opacity-60' : ''}
onPress={() => { onPress={() => {
navigate('/dns') navigate('/dns')
}} }}
@ -68,14 +80,14 @@ const DNSCard: React.FC<Props> = (props) => {
transition, transition,
zIndex: isDragging ? 'calc(infinity)' : undefined zIndex: isDragging ? 'calc(infinity)' : undefined
}} }}
className={`${dnsCardStatus} ${!controlDns ? 'hidden' : ''} dns-card`} className={`${dnsCardStatus} dns-card`}
> >
<Card <Card
fullWidth fullWidth
ref={setNodeRef} ref={setNodeRef}
{...attributes} {...attributes}
{...listeners} {...listeners}
className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''}`} className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''} ${!controlDns ? 'opacity-60' : ''}`}
> >
<CardBody className="pb-1 pt-0 px-0"> <CardBody className="pb-1 pt-0 px-0">
<div className="flex justify-between"> <div className="flex justify-between">
@ -90,8 +102,8 @@ const DNSCard: React.FC<Props> = (props) => {
/> />
</Button> </Button>
<BorderSwitch <BorderSwitch
isShowBorder={match && enable} isShowBorder={match && controlDns}
isSelected={enable} isSelected={controlDns}
isDisabled={tun?.enable} isDisabled={tun?.enable}
onValueChange={onChange} onValueChange={onChange}
/> />

View File

@ -42,13 +42,14 @@ const SniffCard: React.FC<Props> = (props) => {
if (iconOnly) { if (iconOnly) {
return ( return (
<div className={`${sniffCardStatus} ${!controlSniff ? 'hidden' : ''} flex justify-center`}> <div className={`${sniffCardStatus} flex justify-center`}>
<Tooltip content={t('sider.cards.sniff')} placement="right"> <Tooltip content={t('sider.cards.sniff')} placement="right">
<Button <Button
size="sm" size="sm"
isIconOnly isIconOnly
color={match ? 'primary' : 'default'} color={match ? 'primary' : 'default'}
variant={match ? 'solid' : 'light'} variant={match ? 'solid' : 'light'}
className={!enable ? 'opacity-60' : ''}
onPress={() => { onPress={() => {
navigate('/sniffer') navigate('/sniffer')
}} }}
@ -68,14 +69,14 @@ const SniffCard: React.FC<Props> = (props) => {
transition, transition,
zIndex: isDragging ? 'calc(infinity)' : undefined zIndex: isDragging ? 'calc(infinity)' : undefined
}} }}
className={`${sniffCardStatus} ${!controlSniff ? 'hidden' : ''} sniff-card`} className={`${sniffCardStatus} sniff-card`}
> >
<Card <Card
fullWidth fullWidth
ref={setNodeRef} ref={setNodeRef}
{...attributes} {...attributes}
{...listeners} {...listeners}
className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''}`} className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''} ${!enable ? 'opacity-60' : ''}`}
> >
<CardBody className="pb-1 pt-0 px-0"> <CardBody className="pb-1 pt-0 px-0">
<div className="flex justify-between"> <div className="flex justify-between">

View File

@ -58,6 +58,7 @@ const SysproxySwitcher: React.FC<Props> = (props) => {
isIconOnly isIconOnly
color={match ? 'primary' : 'default'} color={match ? 'primary' : 'default'}
variant={match ? 'solid' : 'light'} variant={match ? 'solid' : 'light'}
className={!enable ? 'opacity-60' : ''}
onPress={() => { onPress={() => {
navigate('/sysproxy') navigate('/sysproxy')
}} }}
@ -84,7 +85,7 @@ const SysproxySwitcher: React.FC<Props> = (props) => {
ref={setNodeRef} ref={setNodeRef}
{...attributes} {...attributes}
{...listeners} {...listeners}
className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''}`} className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''} ${!enable ? 'opacity-60' : ''}`}
> >
<CardBody className="pb-1 pt-0 px-0"> <CardBody className="pb-1 pt-0 px-0">
<div className="flex justify-between"> <div className="flex justify-between">

View File

@ -56,6 +56,7 @@ const TunSwitcher: React.FC<Props> = (props) => {
isIconOnly isIconOnly
color={match ? 'primary' : 'default'} color={match ? 'primary' : 'default'}
variant={match ? 'solid' : 'light'} variant={match ? 'solid' : 'light'}
className={!enable ? 'opacity-60' : ''}
onPress={() => { onPress={() => {
navigate('/tun') navigate('/tun')
}} }}
@ -82,7 +83,7 @@ const TunSwitcher: React.FC<Props> = (props) => {
ref={setNodeRef} ref={setNodeRef}
{...attributes} {...attributes}
{...listeners} {...listeners}
className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''}`} className={`${match ? 'bg-primary' : 'hover:bg-primary/30'} ${isDragging ? 'scale-[0.97] tap-highlight-transparent' : ''} ${!enable ? 'opacity-60' : ''}`}
> >
<CardBody className="pb-1 pt-0 px-0"> <CardBody className="pb-1 pt-0 px-0">
<div className="flex justify-between"> <div className="flex justify-between">

View File

@ -71,13 +71,34 @@ export const ProfileConfigProvider: React.FC<{ children: ReactNode }> = ({ child
} }
const changeCurrentProfile = async (id: string): Promise<void> => { const changeCurrentProfile = async (id: string): Promise<void> => {
if (profileConfig?.current === id) {
return
}
// 乐观更新:立即更新 UI 状态,提供即时反馈
if (profileConfig) {
const optimisticUpdate = { ...profileConfig, current: id }
mutateProfileConfig(optimisticUpdate, false)
}
try { try {
await change(id) // 异步执行后台切换,不阻塞 UI
change(id).then(() => {
window.electron.ipcRenderer.send('updateTrayMenu')
mutateProfileConfig()
}).catch((e) => {
const errorMsg = e?.message || String(e)
// 处理 IPC 超时错误
if (errorMsg.includes('reply was never sent')) {
setTimeout(() => mutateProfileConfig(), 1000)
} else {
alert(`切换 Profile 失败: ${errorMsg}`)
mutateProfileConfig()
}
})
} catch (e) { } catch (e) {
alert(e) alert(`切换 Profile 失败: ${e}`)
} finally {
mutateProfileConfig() mutateProfileConfig()
window.electron.ipcRenderer.send('updateTrayMenu')
} }
} }

View File

@ -98,7 +98,7 @@
"mihomo.cpuPriority.low": "Low", "mihomo.cpuPriority.low": "Low",
"mihomo.workDir.title": "Separate Work Directory for Different Subscriptions", "mihomo.workDir.title": "Separate Work Directory for Different Subscriptions",
"mihomo.workDir.tooltip": "Enable to avoid conflicts when different subscriptions have proxy groups with the same name", "mihomo.workDir.tooltip": "Enable to avoid conflicts when different subscriptions have proxy groups with the same name",
"mihomo.controlDns": "Control DNS Settings", "mihomo.controlDns": "Override DNS Settings",
"mihomo.controlSniff": "Control Domain Sniffing", "mihomo.controlSniff": "Control Domain Sniffing",
"mihomo.autoCloseConnection": "Auto Close Connection", "mihomo.autoCloseConnection": "Auto Close Connection",
"mihomo.pauseSSID.title": "Direct Connection for Specific WiFi SSIDs", "mihomo.pauseSSID.title": "Direct Connection for Specific WiFi SSIDs",
@ -216,7 +216,9 @@
"sider.cards.override": "Override", "sider.cards.override": "Override",
"sider.cards.connections": "Connections", "sider.cards.connections": "Connections",
"sider.cards.core": "Core Settings", "sider.cards.core": "Core Settings",
"sider.cards.dns": "DNS", "sider.cards.dns": "DNS OVR",
"sider.cards.dns.originalConfig": "Using Original Config",
"sider.cards.dns.overrideMode": "Override Mode",
"sider.cards.sniff": "Sniffing", "sider.cards.sniff": "Sniffing",
"sider.cards.logs": "Logs", "sider.cards.logs": "Logs",
"sider.cards.substore": "Sub-Store", "sider.cards.substore": "Sub-Store",
@ -316,6 +318,7 @@
"tun.notifications.firewallResetSuccess": "Firewall Reset Successful", "tun.notifications.firewallResetSuccess": "Firewall Reset Successful",
"tun.error.tunPermissionDenied": "TUN interface start failed, please try to manually grant core permissions", "tun.error.tunPermissionDenied": "TUN interface start failed, please try to manually grant core permissions",
"dns.title": "DNS Settings", "dns.title": "DNS Settings",
"dns.enable.title": "Enable DNS",
"dns.enhancedMode.title": "Domain Mapping Mode", "dns.enhancedMode.title": "Domain Mapping Mode",
"dns.enhancedMode.fakeIp": "Fake IP", "dns.enhancedMode.fakeIp": "Fake IP",
"dns.enhancedMode.redirHost": "Real IP", "dns.enhancedMode.redirHost": "Real IP",
@ -513,7 +516,7 @@
"guide.override.title": "Override", "guide.override.title": "Override",
"guide.override.description": "Mihomo Party provides powerful override functionality to customize your imported subscription configurations, such as adding rules and customizing proxy groups. You can directly import override files written by others or write your own. <b>Remember to enable the override file on the subscription you want to override</b>. For override file syntax, please refer to the <a href=\"https://mihomo.party/docs/guide/override\" target=\"_blank\">official documentation</a>.", "guide.override.description": "Mihomo Party provides powerful override functionality to customize your imported subscription configurations, such as adding rules and customizing proxy groups. You can directly import override files written by others or write your own. <b>Remember to enable the override file on the subscription you want to override</b>. For override file syntax, please refer to the <a href=\"https://mihomo.party/docs/guide/override\" target=\"_blank\">official documentation</a>.",
"guide.dns.title": "DNS", "guide.dns.title": "DNS",
"guide.dns.description": "The software takes control of the core's DNS settings by default. If you need to use the DNS settings from your subscription configuration, you can disable 'Control DNS Settings' in the application settings. The same applies to domain sniffing.", "guide.dns.description": "The software overrides subscription DNS settings with application DNS settings by default. If you need to use the DNS settings from your subscription configuration, you can disable 'Override DNS Settings' in the application settings. The same applies to domain sniffing.",
"guide.end.title": "Tutorial Complete", "guide.end.title": "Tutorial Complete",
"guide.end.description": "Now that you understand the basic usage of the software, import your subscription and start using it. Enjoy!\nYou can also join our official <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram group</a> for the latest news." "guide.end.description": "Now that you understand the basic usage of the software, import your subscription and start using it. Enjoy!\nYou can also join our official <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram group</a> for the latest news."
} }

View File

@ -101,7 +101,7 @@
"mihomo.cpuPriority.low": "低", "mihomo.cpuPriority.low": "低",
"mihomo.workDir.title": "不同订阅使用独立工作目录", "mihomo.workDir.title": "不同订阅使用独立工作目录",
"mihomo.workDir.tooltip": "启用后可避免不同订阅中存在相同名称的代理组时发生冲突", "mihomo.workDir.tooltip": "启用后可避免不同订阅中存在相同名称的代理组时发生冲突",
"mihomo.controlDns": "控制 DNS 设置", "mihomo.controlDns": "覆写 DNS 设置",
"mihomo.controlSniff": "控制域名嗅探", "mihomo.controlSniff": "控制域名嗅探",
"mihomo.autoCloseConnection": "自动关闭连接", "mihomo.autoCloseConnection": "自动关闭连接",
"mihomo.pauseSSID.title": "指定 WiFi SSID 直连", "mihomo.pauseSSID.title": "指定 WiFi SSID 直连",
@ -216,7 +216,9 @@
"sider.cards.override": "覆写", "sider.cards.override": "覆写",
"sider.cards.connections": "连接", "sider.cards.connections": "连接",
"sider.cards.core": "内核设置", "sider.cards.core": "内核设置",
"sider.cards.dns": "DNS", "sider.cards.dns": "DNS覆写",
"sider.cards.dns.originalConfig": "使用原始配置",
"sider.cards.dns.overrideMode": "覆写模式",
"sider.cards.sniff": "域名嗅探", "sider.cards.sniff": "域名嗅探",
"sider.cards.logs": "日志", "sider.cards.logs": "日志",
"sider.cards.substore": "Sub-Store", "sider.cards.substore": "Sub-Store",
@ -316,6 +318,7 @@
"tun.notifications.firewallResetSuccess": "防火墙重设成功", "tun.notifications.firewallResetSuccess": "防火墙重设成功",
"tun.error.tunPermissionDenied": "虚拟网卡启动失败,请尝试手动授予内核权限", "tun.error.tunPermissionDenied": "虚拟网卡启动失败,请尝试手动授予内核权限",
"dns.title": "DNS 设置", "dns.title": "DNS 设置",
"dns.enable.title": "启用 DNS",
"dns.enhancedMode.title": "域名映射模式", "dns.enhancedMode.title": "域名映射模式",
"dns.enhancedMode.fakeIp": "虚假 IP", "dns.enhancedMode.fakeIp": "虚假 IP",
"dns.enhancedMode.redirHost": "真实 IP", "dns.enhancedMode.redirHost": "真实 IP",
@ -513,7 +516,7 @@
"guide.override.title": "覆写", "guide.override.title": "覆写",
"guide.override.description": "Mihomo Party 提供强大的覆写功能,可以对您导入的订阅配置进行个性化修改,如添加规则、自定义代理组等,您可以直接导入别人写好的覆写文件,也可以自己动手编写,<b>编辑好覆写文件一定要记得在需要覆写的订阅上启用</b>,覆写文件的语法请参考 <a href=\"https://mihomo.party/docs/guide/override\" target=\"_blank\">官方文档</a>", "guide.override.description": "Mihomo Party 提供强大的覆写功能,可以对您导入的订阅配置进行个性化修改,如添加规则、自定义代理组等,您可以直接导入别人写好的覆写文件,也可以自己动手编写,<b>编辑好覆写文件一定要记得在需要覆写的订阅上启用</b>,覆写文件的语法请参考 <a href=\"https://mihomo.party/docs/guide/override\" target=\"_blank\">官方文档</a>",
"guide.dns.title": "DNS", "guide.dns.title": "DNS",
"guide.dns.description": "软件默认接管了内核的 DNS 设置,如果您需要使用订阅配置中的 DNS 设置,可以到应用设置中关闭\"接管 DNS 设置\",域名嗅探同理", "guide.dns.description": "软件默认使用应用的 DNS 设置覆写订阅配置,如果您需要使用订阅配置中的 DNS 设置,可以到应用设置中关闭\"覆写 DNS 设置\",域名嗅探同理",
"guide.end.title": "教程结束", "guide.end.title": "教程结束",
"guide.end.description": "现在您已经了解了软件的基本用法,导入您的订阅开始使用吧,祝您使用愉快!\n您还可以加入我们的官方 <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram 群组</a> 获取最新资讯" "guide.end.description": "现在您已经了解了软件的基本用法,导入您的订阅开始使用吧,祝您使用愉快!\n您还可以加入我们的官方 <a href=\"https://t.me/mihomo_party_group\" target=\"_blank\">Telegram 群组</a> 获取最新资讯"
} }

View File

@ -273,7 +273,7 @@ const Connections: React.FC = () => {
</div> </div>
<Divider /> <Divider />
</div> </div>
<div className="h-[calc(100vh-100px)] mt-[1px]"> <div className="h-[calc(100vh-100px)] mt-px">
<Virtuoso <Virtuoso
data={filteredConnections} data={filteredConnections}
itemContent={(i, connection) => ( itemContent={(i, connection) => (

View File

@ -16,6 +16,7 @@ const DNS: React.FC = () => {
const { nameserverPolicy, useNameserverPolicy } = appConfig || {} const { nameserverPolicy, useNameserverPolicy } = appConfig || {}
const { dns, hosts } = controledMihomoConfig || {} const { dns, hosts } = controledMihomoConfig || {}
const { const {
enable = true,
ipv6 = false, ipv6 = false,
'fake-ip-range': fakeIPRange = '198.18.0.1/16', 'fake-ip-range': fakeIPRange = '198.18.0.1/16',
'fake-ip-filter': fakeIPFilter = [ 'fake-ip-filter': fakeIPFilter = [
@ -40,6 +41,7 @@ const DNS: React.FC = () => {
} = dns || {} } = dns || {}
const [changed, setChanged] = useState(false) const [changed, setChanged] = useState(false)
const [values, originSetValues] = useState({ const [values, originSetValues] = useState({
enable,
ipv6, ipv6,
useHosts, useHosts,
enhancedMode, enhancedMode,
@ -143,6 +145,7 @@ const DNS: React.FC = () => {
color="primary" color="primary"
onPress={() => { onPress={() => {
const dnsConfig = { const dnsConfig = {
enable: values.enable,
ipv6: values.ipv6, ipv6: values.ipv6,
'fake-ip-range': values.fakeIPRange, 'fake-ip-range': values.fakeIPRange,
'fake-ip-filter': values.fakeIPFilter, 'fake-ip-filter': values.fakeIPFilter,
@ -177,6 +180,15 @@ const DNS: React.FC = () => {
} }
> >
<SettingCard> <SettingCard>
<SettingItem title={t('dns.enable.title')} divider>
<Switch
size="sm"
isSelected={values.enable}
onValueChange={(v) => {
setValues({ ...values, enable: v })
}}
/>
</SettingItem>
<SettingItem title={t('dns.enhancedMode.title')} divider> <SettingItem title={t('dns.enhancedMode.title')} divider>
<Tabs <Tabs
size="sm" size="sm"
@ -264,7 +276,7 @@ const DNS: React.FC = () => {
{[...values.nameserverPolicy, { domain: '', value: '' }].map( {[...values.nameserverPolicy, { domain: '', value: '' }].map(
({ domain, value }, index) => ( ({ domain, value }, index) => (
<div key={index} className="flex mb-2"> <div key={index} className="flex mb-2">
<div className="flex-[4]"> <div className="flex-4">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth
@ -281,7 +293,7 @@ const DNS: React.FC = () => {
/> />
</div> </div>
<span className="mx-2">:</span> <span className="mx-2">:</span>
<div className="flex-[6] flex"> <div className="flex-6 flex">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth
@ -332,7 +344,7 @@ const DNS: React.FC = () => {
<h3 className="mb-2">{t('dns.customHosts.list')}</h3> <h3 className="mb-2">{t('dns.customHosts.list')}</h3>
{[...values.hosts, { domain: '', value: '' }].map(({ domain, value }, index) => ( {[...values.hosts, { domain: '', value: '' }].map(({ domain, value }, index) => (
<div key={index} className="flex mb-2"> <div key={index} className="flex mb-2">
<div className="flex-[4]"> <div className="flex-4">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth
@ -349,7 +361,7 @@ const DNS: React.FC = () => {
/> />
</div> </div>
<span className="mx-2">:</span> <span className="mx-2">:</span>
<div className="flex-[6] flex"> <div className="flex-6 flex">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth

View File

@ -109,7 +109,7 @@ const Logs: React.FC = () => {
</div> </div>
<Divider /> <Divider />
</div> </div>
<div className="h-[calc(100vh-100px)] mt-[1px]"> <div className="h-[calc(100vh-100px)] mt-px">
<Virtuoso <Virtuoso
ref={virtuosoRef} ref={virtuosoRef}
data={filteredLogs} data={filteredLogs}

View File

@ -652,7 +652,7 @@ const Mihomo: React.FC = () => {
const [user, pass] = auth.split(':') const [user, pass] = auth.split(':')
return ( return (
<div key={index} className="flex mb-2"> <div key={index} className="flex mb-2">
<div className="flex-[4]"> <div className="flex-4">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth
@ -672,7 +672,7 @@ const Mihomo: React.FC = () => {
/> />
</div> </div>
<span className="mx-2">:</span> <span className="mx-2">:</span>
<div className="flex-[6] flex"> <div className="flex-6 flex">
<Input <Input
size="sm" size="sm"
fullWidth fullWidth

View File

@ -85,7 +85,7 @@ const Profiles: React.FC = () => {
<div> <div>
{sub.tag?.map((tag) => { {sub.tag?.map((tag) => {
return ( return (
<Chip key={tag} size="sm" className="ml-1" radius="sm"> <Chip key={tag} size="sm" className="ml-1" radius="xs">
{tag} {tag}
</Chip> </Chip>
) )
@ -108,7 +108,7 @@ const Profiles: React.FC = () => {
<div> <div>
{sub.tag?.map((tag) => { {sub.tag?.map((tag) => {
return ( return (
<Chip key={tag} size="sm" className="ml-1" radius="sm"> <Chip key={tag} size="sm" className="ml-1" radius="xs">
{tag} {tag}
</Chip> </Chip>
) )

View File

@ -324,7 +324,7 @@ const Proxies: React.FC = () => {
<Avatar <Avatar
className="bg-transparent mr-2" className="bg-transparent mr-2"
size="sm" size="sm"
radius="sm" radius="xs"
src={ src={
groups[index].icon.startsWith('<svg') groups[index].icon.startsWith('<svg')
? `data:image/svg+xml;utf8,${groups[index].icon}` ? `data:image/svg+xml;utf8,${groups[index].icon}`

View File

@ -38,7 +38,7 @@ const Rules: React.FC = () => {
</div> </div>
<Divider /> <Divider />
</div> </div>
<div className="h-[calc(100vh-100px)] mt-[1px]"> <div className="h-[calc(100vh-100px)] mt-px">
<Virtuoso <Virtuoso
data={filteredRules} data={filteredRules}
itemContent={(i, rule) => ( itemContent={(i, rule) => (

View File

@ -1,14 +0,0 @@
/** @type {import('tailwindcss').Config} */
const { heroui } = require('@heroui/react')
module.exports = {
content: [
'./src/renderer/src/**/*.{js,ts,jsx,tsx}',
'./node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}'
],
theme: {
extend: {}
},
darkMode: 'class',
plugins: [heroui()]
}

View File

@ -3,6 +3,7 @@
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "src/shared/**/*"], "include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*", "src/shared/**/*"],
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"types": ["electron-vite/node"] "types": ["electron-vite/node"],
"moduleResolution": "bundler"
} }
} }