fix click event

This commit is contained in:
pompurin404 2024-08-10 16:11:48 +08:00
parent 72417e8ef6
commit 25358201cc
No known key found for this signature in database
10 changed files with 122 additions and 87 deletions

View File

@ -1,6 +1,6 @@
import { getControledMihomoConfig } from './controledMihomo' import { getControledMihomoConfig } from './controledMihomo'
import { profileConfigPath, profilePath } from '../utils/dirs' import { profileConfigPath, profilePath } from '../utils/dirs'
import { startCore } from '../core/manager' import { restartCore } from '../core/manager'
import { getAppConfig } from './app' import { getAppConfig } from './app'
import { window } from '..' import { window } from '..'
import axios from 'axios' import axios from 'axios'
@ -8,7 +8,6 @@ import yaml from 'yaml'
import fs from 'fs' import fs from 'fs'
import { dialog } from 'electron' import { dialog } from 'electron'
import { addProfileUpdater } from '../core/profileUpdater' import { addProfileUpdater } from '../core/profileUpdater'
import { pauseWebsockets } from '../core/mihomoApi'
let profileConfig: IProfileConfig // profile.yaml let profileConfig: IProfileConfig // profile.yaml
@ -28,9 +27,7 @@ export async function changeCurrentProfile(id: string): Promise<void> {
const oldId = getProfileConfig().current const oldId = getProfileConfig().current
profileConfig.current = id profileConfig.current = id
try { try {
const recover = pauseWebsockets() await restartCore()
await startCore()
recover()
} catch (e) { } catch (e) {
profileConfig.current = oldId profileConfig.current = oldId
} finally { } finally {
@ -180,9 +177,7 @@ export function getProfileStr(id: string): string {
export async function setProfileStr(id: string, content: string): Promise<void> { export async function setProfileStr(id: string, content: string): Promise<void> {
fs.writeFileSync(profilePath(id), content, 'utf-8') fs.writeFileSync(profilePath(id), content, 'utf-8')
if (id === getProfileConfig().current) { if (id === getProfileConfig().current) {
const recover = pauseWebsockets() await restartCore()
await startCore()
recover()
} }
} }

View File

@ -10,6 +10,7 @@ import { generateProfile } from '../resolve/factory'
import { getAppConfig, setAppConfig } from '../config' import { getAppConfig, setAppConfig } from '../config'
import { dialog, safeStorage } from 'electron' import { dialog, safeStorage } from 'electron'
import fs from 'fs' import fs from 'fs'
import { pauseWebsockets } from './mihomoApi'
let child: ChildProcess let child: ChildProcess
let retry = 10 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> { export function checkProfile(): Promise<void> {
const corePath = mihomoCorePath(getAppConfig().core ?? 'mihomo') const corePath = mihomoCorePath(getAppConfig().core ?? 'mihomo')
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@ -14,7 +14,6 @@ import {
mihomoUpgradeGeo, mihomoUpgradeGeo,
mihomoVersion, mihomoVersion,
patchMihomoConfig, patchMihomoConfig,
pauseWebsockets,
startMihomoConnections, startMihomoConnections,
startMihomoLogs, startMihomoLogs,
stopMihomoConnections, stopMihomoConnections,
@ -36,7 +35,7 @@ import {
setProfileStr, setProfileStr,
updateProfileItem updateProfileItem
} from '../config' } from '../config'
import { isEncryptionAvailable, startCore } from '../core/manager' import { isEncryptionAvailable, restartCore } from '../core/manager'
import { triggerSysProxy } from '../resolve/sysproxy' import { triggerSysProxy } from '../resolve/sysproxy'
import { checkUpdate } from '../resolve/autoUpdater' import { checkUpdate } from '../resolve/autoUpdater'
import { exePath, mihomoCorePath, mihomoWorkConfigPath, resourcesDir } from './dirs' import { exePath, mihomoCorePath, mihomoWorkConfigPath, resourcesDir } from './dirs'
@ -80,11 +79,7 @@ export function registerIpcMainHandlers(): void {
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id)) ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item)) ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id)) ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id))
ipcMain.handle('restartCore', async () => { ipcMain.handle('restartCore', restartCore)
const recover = pauseWebsockets()
await startCore()
recover()
})
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable)) ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable) ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str)) ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))

View File

@ -19,7 +19,7 @@ const BasePasswordModal: React.FC<Props> = (props) => {
const [password, setPassword] = useState('') const [password, setPassword] = useState('')
return ( return (
<Modal hideCloseButton isOpen={true}> <Modal backdrop="blur" hideCloseButton isOpen={true}>
<ModalContent> <ModalContent>
<ModalHeader className="flex">root密码</ModalHeader> <ModalHeader className="flex">root密码</ModalHeader>
<ModalBody> <ModalBody>

View File

@ -8,7 +8,14 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
const { connection, onClose } = props const { connection, onClose } = props
return ( return (
<Modal size="xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside"> <Modal
backdrop="blur"
size="xl"
hideCloseButton
isOpen={true}
onOpenChange={onClose}
scrollBehavior="inside"
>
<ModalContent> <ModalContent>
<ModalHeader className="flex"></ModalHeader> <ModalHeader className="flex"></ModalHeader>
<ModalBody> <ModalBody>

View File

@ -32,7 +32,14 @@ const EditFileModal: React.FC<Props> = (props) => {
}, []) }, [])
return ( 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)]"> <ModalContent className="h-full w-[calc(100%-100px)]">
<ModalHeader className="flex"></ModalHeader> <ModalHeader className="flex"></ModalHeader>
<ModalBody className="h-full"> <ModalBody className="h-full">

View File

@ -25,7 +25,13 @@ const EditInfoModal: React.FC<Props> = (props) => {
} }
return ( return (
<Modal hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside"> <Modal
backdrop="blur"
hideCloseButton
isOpen={true}
onOpenChange={onClose}
scrollBehavior="inside"
>
<ModalContent> <ModalContent>
<ModalHeader className="flex"></ModalHeader> <ModalHeader className="flex"></ModalHeader>
<ModalBody> <ModalBody>

View File

@ -31,7 +31,14 @@ const ConfigViewer: React.FC<Props> = (props) => {
}, []) }, [])
return ( 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)]"> <ModalContent className="h-full w-[calc(100%-100px)]">
<ModalHeader className="flex"></ModalHeader> <ModalHeader className="flex"></ModalHeader>
<ModalBody className="h-full"> <ModalBody className="h-full">

View File

@ -32,86 +32,90 @@ const ProfileCard: React.FC = () => {
const total = extra?.total ?? 0 const total = extra?.total ?? 0
return ( return (
<Card <>
fullWidth
className={`mb-2 ${match ? 'bg-primary' : ''}`}
isPressable
onPress={() => navigate('/profiles')}
>
{showRuntimeConfig && <ConfigViewer onClose={() => setShowRuntimeConfig(false)} />} {showRuntimeConfig && <ConfigViewer onClose={() => setShowRuntimeConfig(false)} />}
<CardBody className="pb-1"> <Card
<div className="flex justify-between h-[32px]"> fullWidth
<h3 className={`mb-2 ${match ? 'bg-primary' : ''}`}
className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `} isPressable
> onPress={() => navigate('/profiles')}
{info?.name} >
</h3> <CardBody className="pb-1">
<div className="flex"> <div className="flex justify-between h-[32px]">
<Button <h3
isIconOnly className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `}
size="sm"
title="查看当前运行时配置"
variant="light"
color="default"
onPress={() => {
setShowRuntimeConfig(true)
}}
> >
<CgLoadbarDoc className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`} /> {info?.name}
</Button> </h3>
{info.type === 'remote' && ( <div className="flex">
<Button <Button
isIconOnly isIconOnly
size="sm" size="sm"
disabled={updating} title="查看当前运行时配置"
variant="light" variant="light"
color="default" color="default"
onPress={() => { onPress={() => {
setUpdating(true) setShowRuntimeConfig(true)
addProfileItem(info).finally(() => {
setUpdating(false)
})
}} }}
> >
<IoMdRefresh <CgLoadbarDoc
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'} ${updating ? 'animate-spin' : ''}`} className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`}
/> />
</Button> </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>
</div> {info.type === 'remote' && (
{info.type === 'remote' && ( <div
<div className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'} `}
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'}`}
> >
<small>{extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}</small>
</Chip> <small>{dayjs(info.updated).fromNow()}</small>
</div> </div>
)} )}
</CardBody> {info.type === 'local' && (
<CardFooter className="pt-0"> <div
{extra && ( className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'}`}
<Progress >
className="w-full" <Chip
classNames={{ indicator: match ? 'bg-white' : 'bg-foreground', label: 'select-none' }} size="sm"
value={calcPercent(extra?.upload, extra?.download, extra?.total)} variant="bordered"
/> className={`${match ? 'text-white border-white' : 'border-primary text-primary'}`}
)} >
</CardFooter>
</Card> </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>
</>
) )
} }

View File

@ -24,7 +24,14 @@ const PacEditorViewer: React.FC<Props> = (props) => {
} }
return ( 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)]"> <ModalContent className="h-full w-[calc(100%-100px)]">
<ModalHeader className="flex">PAC脚本</ModalHeader> <ModalHeader className="flex">PAC脚本</ModalHeader>
<ModalBody className="h-full"> <ModalBody className="h-full">