mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix click event
This commit is contained in:
parent
72417e8ef6
commit
25358201cc
@ -1,6 +1,6 @@
|
||||
import { getControledMihomoConfig } from './controledMihomo'
|
||||
import { profileConfigPath, profilePath } from '../utils/dirs'
|
||||
import { startCore } from '../core/manager'
|
||||
import { restartCore } from '../core/manager'
|
||||
import { getAppConfig } from './app'
|
||||
import { window } from '..'
|
||||
import axios from 'axios'
|
||||
@ -8,7 +8,6 @@ import yaml from 'yaml'
|
||||
import fs from 'fs'
|
||||
import { dialog } from 'electron'
|
||||
import { addProfileUpdater } from '../core/profileUpdater'
|
||||
import { pauseWebsockets } from '../core/mihomoApi'
|
||||
|
||||
let profileConfig: IProfileConfig // profile.yaml
|
||||
|
||||
@ -28,9 +27,7 @@ export async function changeCurrentProfile(id: string): Promise<void> {
|
||||
const oldId = getProfileConfig().current
|
||||
profileConfig.current = id
|
||||
try {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
await restartCore()
|
||||
} catch (e) {
|
||||
profileConfig.current = oldId
|
||||
} finally {
|
||||
@ -180,9 +177,7 @@ export function getProfileStr(id: string): string {
|
||||
export async function setProfileStr(id: string, content: string): Promise<void> {
|
||||
fs.writeFileSync(profilePath(id), content, 'utf-8')
|
||||
if (id === getProfileConfig().current) {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
await restartCore()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import { generateProfile } from '../resolve/factory'
|
||||
import { getAppConfig, setAppConfig } from '../config'
|
||||
import { dialog, safeStorage } from 'electron'
|
||||
import fs from 'fs'
|
||||
import { pauseWebsockets } from './mihomoApi'
|
||||
|
||||
let child: ChildProcess
|
||||
let retry = 10
|
||||
@ -82,6 +83,12 @@ export function stopCore(): void {
|
||||
}
|
||||
}
|
||||
|
||||
export async function restartCore(): Promise<void> {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
}
|
||||
|
||||
export function checkProfile(): Promise<void> {
|
||||
const corePath = mihomoCorePath(getAppConfig().core ?? 'mihomo')
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@ -14,7 +14,6 @@ import {
|
||||
mihomoUpgradeGeo,
|
||||
mihomoVersion,
|
||||
patchMihomoConfig,
|
||||
pauseWebsockets,
|
||||
startMihomoConnections,
|
||||
startMihomoLogs,
|
||||
stopMihomoConnections,
|
||||
@ -36,7 +35,7 @@ import {
|
||||
setProfileStr,
|
||||
updateProfileItem
|
||||
} from '../config'
|
||||
import { isEncryptionAvailable, startCore } from '../core/manager'
|
||||
import { isEncryptionAvailable, restartCore } from '../core/manager'
|
||||
import { triggerSysProxy } from '../resolve/sysproxy'
|
||||
import { checkUpdate } from '../resolve/autoUpdater'
|
||||
import { exePath, mihomoCorePath, mihomoWorkConfigPath, resourcesDir } from './dirs'
|
||||
@ -80,11 +79,7 @@ export function registerIpcMainHandlers(): void {
|
||||
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
|
||||
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
|
||||
ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id))
|
||||
ipcMain.handle('restartCore', async () => {
|
||||
const recover = pauseWebsockets()
|
||||
await startCore()
|
||||
recover()
|
||||
})
|
||||
ipcMain.handle('restartCore', restartCore)
|
||||
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
||||
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
||||
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
||||
|
||||
@ -19,7 +19,7 @@ const BasePasswordModal: React.FC<Props> = (props) => {
|
||||
const [password, setPassword] = useState('')
|
||||
|
||||
return (
|
||||
<Modal hideCloseButton isOpen={true}>
|
||||
<Modal backdrop="blur" hideCloseButton isOpen={true}>
|
||||
<ModalContent>
|
||||
<ModalHeader className="flex">请输入root密码</ModalHeader>
|
||||
<ModalBody>
|
||||
|
||||
@ -8,7 +8,14 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
|
||||
const { connection, onClose } = props
|
||||
|
||||
return (
|
||||
<Modal size="xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
|
||||
<Modal
|
||||
backdrop="blur"
|
||||
size="xl"
|
||||
hideCloseButton
|
||||
isOpen={true}
|
||||
onOpenChange={onClose}
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent>
|
||||
<ModalHeader className="flex">连接详情</ModalHeader>
|
||||
<ModalBody>
|
||||
|
||||
@ -32,7 +32,14 @@ const EditFileModal: React.FC<Props> = (props) => {
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
|
||||
<Modal
|
||||
backdrop="blur"
|
||||
size="5xl"
|
||||
hideCloseButton
|
||||
isOpen={true}
|
||||
onOpenChange={onClose}
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent className="h-full w-[calc(100%-100px)]">
|
||||
<ModalHeader className="flex">编辑订阅</ModalHeader>
|
||||
<ModalBody className="h-full">
|
||||
|
||||
@ -25,7 +25,13 @@ const EditInfoModal: React.FC<Props> = (props) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
|
||||
<Modal
|
||||
backdrop="blur"
|
||||
hideCloseButton
|
||||
isOpen={true}
|
||||
onOpenChange={onClose}
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent>
|
||||
<ModalHeader className="flex">编辑信息</ModalHeader>
|
||||
<ModalBody>
|
||||
|
||||
@ -31,7 +31,14 @@ const ConfigViewer: React.FC<Props> = (props) => {
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
|
||||
<Modal
|
||||
backdrop="blur"
|
||||
size="5xl"
|
||||
hideCloseButton
|
||||
isOpen={true}
|
||||
onOpenChange={onClose}
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent className="h-full w-[calc(100%-100px)]">
|
||||
<ModalHeader className="flex">当前运行时配置</ModalHeader>
|
||||
<ModalBody className="h-full">
|
||||
|
||||
@ -32,86 +32,90 @@ const ProfileCard: React.FC = () => {
|
||||
const total = extra?.total ?? 0
|
||||
|
||||
return (
|
||||
<Card
|
||||
fullWidth
|
||||
className={`mb-2 ${match ? 'bg-primary' : ''}`}
|
||||
isPressable
|
||||
onPress={() => navigate('/profiles')}
|
||||
>
|
||||
<>
|
||||
{showRuntimeConfig && <ConfigViewer onClose={() => setShowRuntimeConfig(false)} />}
|
||||
<CardBody className="pb-1">
|
||||
<div className="flex justify-between h-[32px]">
|
||||
<h3
|
||||
className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `}
|
||||
>
|
||||
{info?.name}
|
||||
</h3>
|
||||
<div className="flex">
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
title="查看当前运行时配置"
|
||||
variant="light"
|
||||
color="default"
|
||||
onPress={() => {
|
||||
setShowRuntimeConfig(true)
|
||||
}}
|
||||
<Card
|
||||
fullWidth
|
||||
className={`mb-2 ${match ? 'bg-primary' : ''}`}
|
||||
isPressable
|
||||
onPress={() => navigate('/profiles')}
|
||||
>
|
||||
<CardBody className="pb-1">
|
||||
<div className="flex justify-between h-[32px]">
|
||||
<h3
|
||||
className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `}
|
||||
>
|
||||
<CgLoadbarDoc className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`} />
|
||||
</Button>
|
||||
{info.type === 'remote' && (
|
||||
{info?.name}
|
||||
</h3>
|
||||
<div className="flex">
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
disabled={updating}
|
||||
title="查看当前运行时配置"
|
||||
variant="light"
|
||||
color="default"
|
||||
onPress={() => {
|
||||
setUpdating(true)
|
||||
addProfileItem(info).finally(() => {
|
||||
setUpdating(false)
|
||||
})
|
||||
setShowRuntimeConfig(true)
|
||||
}}
|
||||
>
|
||||
<IoMdRefresh
|
||||
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'} ${updating ? 'animate-spin' : ''}`}
|
||||
<CgLoadbarDoc
|
||||
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
{info.type === 'remote' && (
|
||||
<Button
|
||||
isIconOnly
|
||||
size="sm"
|
||||
disabled={updating}
|
||||
variant="light"
|
||||
color="default"
|
||||
onPress={() => {
|
||||
setUpdating(true)
|
||||
addProfileItem(info).finally(() => {
|
||||
setUpdating(false)
|
||||
})
|
||||
}}
|
||||
>
|
||||
<IoMdRefresh
|
||||
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'} ${updating ? 'animate-spin' : ''}`}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{info.type === 'remote' && (
|
||||
<div
|
||||
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'} `}
|
||||
>
|
||||
<small>{extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}</small>
|
||||
<small>{dayjs(info.updated).fromNow()}</small>
|
||||
</div>
|
||||
)}
|
||||
{info.type === 'local' && (
|
||||
<div
|
||||
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'}`}
|
||||
>
|
||||
<Chip
|
||||
size="sm"
|
||||
variant="bordered"
|
||||
className={`${match ? 'text-white border-white' : 'border-primary text-primary'}`}
|
||||
{info.type === 'remote' && (
|
||||
<div
|
||||
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'} `}
|
||||
>
|
||||
本地
|
||||
</Chip>
|
||||
</div>
|
||||
)}
|
||||
</CardBody>
|
||||
<CardFooter className="pt-0">
|
||||
{extra && (
|
||||
<Progress
|
||||
className="w-full"
|
||||
classNames={{ indicator: match ? 'bg-white' : 'bg-foreground', label: 'select-none' }}
|
||||
value={calcPercent(extra?.upload, extra?.download, extra?.total)}
|
||||
/>
|
||||
)}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
<small>{extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}</small>
|
||||
<small>{dayjs(info.updated).fromNow()}</small>
|
||||
</div>
|
||||
)}
|
||||
{info.type === 'local' && (
|
||||
<div
|
||||
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'}`}
|
||||
>
|
||||
<Chip
|
||||
size="sm"
|
||||
variant="bordered"
|
||||
className={`${match ? 'text-white border-white' : 'border-primary text-primary'}`}
|
||||
>
|
||||
本地
|
||||
</Chip>
|
||||
</div>
|
||||
)}
|
||||
</CardBody>
|
||||
<CardFooter className="pt-0">
|
||||
{extra && (
|
||||
<Progress
|
||||
className="w-full"
|
||||
classNames={{ indicator: match ? 'bg-white' : 'bg-foreground', label: 'select-none' }}
|
||||
value={calcPercent(extra?.upload, extra?.download, extra?.total)}
|
||||
/>
|
||||
)}
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,14 @@ const PacEditorViewer: React.FC<Props> = (props) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onCancel} scrollBehavior="inside">
|
||||
<Modal
|
||||
backdrop="blur"
|
||||
size="5xl"
|
||||
hideCloseButton
|
||||
isOpen={true}
|
||||
onOpenChange={onCancel}
|
||||
scrollBehavior="inside"
|
||||
>
|
||||
<ModalContent className="h-full w-[calc(100%-100px)]">
|
||||
<ModalHeader className="flex">编辑PAC脚本</ModalHeader>
|
||||
<ModalBody className="h-full">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user