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 { 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()
}
}

View File

@ -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) => {

View File

@ -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))

View File

@ -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>

View File

@ -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>

View File

@ -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">

View File

@ -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>

View File

@ -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">

View File

@ -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>
</>
)
}

View File

@ -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">