Skip to content

Commit 2535820

Browse files
author
pompurin404
committed
fix click event
1 parent 72417e8 commit 2535820

File tree

10 files changed

+122
-87
lines changed

10 files changed

+122
-87
lines changed

src/main/config/profile.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { getControledMihomoConfig } from './controledMihomo'
22
import { profileConfigPath, profilePath } from '../utils/dirs'
3-
import { startCore } from '../core/manager'
3+
import { restartCore } from '../core/manager'
44
import { getAppConfig } from './app'
55
import { window } from '..'
66
import axios from 'axios'
77
import yaml from 'yaml'
88
import fs from 'fs'
99
import { dialog } from 'electron'
1010
import { addProfileUpdater } from '../core/profileUpdater'
11-
import { pauseWebsockets } from '../core/mihomoApi'
1211

1312
let profileConfig: IProfileConfig // profile.yaml
1413

@@ -28,9 +27,7 @@ export async function changeCurrentProfile(id: string): Promise<void> {
2827
const oldId = getProfileConfig().current
2928
profileConfig.current = id
3029
try {
31-
const recover = pauseWebsockets()
32-
await startCore()
33-
recover()
30+
await restartCore()
3431
} catch (e) {
3532
profileConfig.current = oldId
3633
} finally {
@@ -180,9 +177,7 @@ export function getProfileStr(id: string): string {
180177
export async function setProfileStr(id: string, content: string): Promise<void> {
181178
fs.writeFileSync(profilePath(id), content, 'utf-8')
182179
if (id === getProfileConfig().current) {
183-
const recover = pauseWebsockets()
184-
await startCore()
185-
recover()
180+
await restartCore()
186181
}
187182
}
188183

src/main/core/manager.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { generateProfile } from '../resolve/factory'
1010
import { getAppConfig, setAppConfig } from '../config'
1111
import { dialog, safeStorage } from 'electron'
1212
import fs from 'fs'
13+
import { pauseWebsockets } from './mihomoApi'
1314

1415
let child: ChildProcess
1516
let retry = 10
@@ -82,6 +83,12 @@ export function stopCore(): void {
8283
}
8384
}
8485

86+
export async function restartCore(): Promise<void> {
87+
const recover = pauseWebsockets()
88+
await startCore()
89+
recover()
90+
}
91+
8592
export function checkProfile(): Promise<void> {
8693
const corePath = mihomoCorePath(getAppConfig().core ?? 'mihomo')
8794
return new Promise((resolve, reject) => {

src/main/utils/ipc.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
mihomoUpgradeGeo,
1515
mihomoVersion,
1616
patchMihomoConfig,
17-
pauseWebsockets,
1817
startMihomoConnections,
1918
startMihomoLogs,
2019
stopMihomoConnections,
@@ -36,7 +35,7 @@ import {
3635
setProfileStr,
3736
updateProfileItem
3837
} from '../config'
39-
import { isEncryptionAvailable, startCore } from '../core/manager'
38+
import { isEncryptionAvailable, restartCore } from '../core/manager'
4039
import { triggerSysProxy } from '../resolve/sysproxy'
4140
import { checkUpdate } from '../resolve/autoUpdater'
4241
import { exePath, mihomoCorePath, mihomoWorkConfigPath, resourcesDir } from './dirs'
@@ -80,11 +79,7 @@ export function registerIpcMainHandlers(): void {
8079
ipcMain.handle('changeCurrentProfile', (_e, id) => changeCurrentProfile(id))
8180
ipcMain.handle('addProfileItem', (_e, item) => addProfileItem(item))
8281
ipcMain.handle('removeProfileItem', (_e, id) => removeProfileItem(id))
83-
ipcMain.handle('restartCore', async () => {
84-
const recover = pauseWebsockets()
85-
await startCore()
86-
recover()
87-
})
82+
ipcMain.handle('restartCore', restartCore)
8883
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
8984
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
9085
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))

src/renderer/src/components/base/base-password-modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const BasePasswordModal: React.FC<Props> = (props) => {
1919
const [password, setPassword] = useState('')
2020

2121
return (
22-
<Modal hideCloseButton isOpen={true}>
22+
<Modal backdrop="blur" hideCloseButton isOpen={true}>
2323
<ModalContent>
2424
<ModalHeader className="flex">请输入root密码</ModalHeader>
2525
<ModalBody>

src/renderer/src/components/connections/connection-detail-modal.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
88
const { connection, onClose } = props
99

1010
return (
11-
<Modal size="xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
11+
<Modal
12+
backdrop="blur"
13+
size="xl"
14+
hideCloseButton
15+
isOpen={true}
16+
onOpenChange={onClose}
17+
scrollBehavior="inside"
18+
>
1219
<ModalContent>
1320
<ModalHeader className="flex">连接详情</ModalHeader>
1421
<ModalBody>

src/renderer/src/components/profiles/edit-file-modal.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ const EditFileModal: React.FC<Props> = (props) => {
3232
}, [])
3333

3434
return (
35-
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
35+
<Modal
36+
backdrop="blur"
37+
size="5xl"
38+
hideCloseButton
39+
isOpen={true}
40+
onOpenChange={onClose}
41+
scrollBehavior="inside"
42+
>
3643
<ModalContent className="h-full w-[calc(100%-100px)]">
3744
<ModalHeader className="flex">编辑订阅</ModalHeader>
3845
<ModalBody className="h-full">

src/renderer/src/components/profiles/edit-info-modal.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ const EditInfoModal: React.FC<Props> = (props) => {
2525
}
2626

2727
return (
28-
<Modal hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
28+
<Modal
29+
backdrop="blur"
30+
hideCloseButton
31+
isOpen={true}
32+
onOpenChange={onClose}
33+
scrollBehavior="inside"
34+
>
2935
<ModalContent>
3036
<ModalHeader className="flex">编辑信息</ModalHeader>
3137
<ModalBody>

src/renderer/src/components/sider/config-viewer.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ const ConfigViewer: React.FC<Props> = (props) => {
3131
}, [])
3232

3333
return (
34-
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onClose} scrollBehavior="inside">
34+
<Modal
35+
backdrop="blur"
36+
size="5xl"
37+
hideCloseButton
38+
isOpen={true}
39+
onOpenChange={onClose}
40+
scrollBehavior="inside"
41+
>
3542
<ModalContent className="h-full w-[calc(100%-100px)]">
3643
<ModalHeader className="flex">当前运行时配置</ModalHeader>
3744
<ModalBody className="h-full">

src/renderer/src/components/sider/profile-card.tsx

+70-66
Original file line numberDiff line numberDiff line change
@@ -32,86 +32,90 @@ const ProfileCard: React.FC = () => {
3232
const total = extra?.total ?? 0
3333

3434
return (
35-
<Card
36-
fullWidth
37-
className={`mb-2 ${match ? 'bg-primary' : ''}`}
38-
isPressable
39-
onPress={() => navigate('/profiles')}
40-
>
35+
<>
4136
{showRuntimeConfig && <ConfigViewer onClose={() => setShowRuntimeConfig(false)} />}
42-
<CardBody className="pb-1">
43-
<div className="flex justify-between h-[32px]">
44-
<h3
45-
className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `}
46-
>
47-
{info?.name}
48-
</h3>
49-
<div className="flex">
50-
<Button
51-
isIconOnly
52-
size="sm"
53-
title="查看当前运行时配置"
54-
variant="light"
55-
color="default"
56-
onPress={() => {
57-
setShowRuntimeConfig(true)
58-
}}
37+
<Card
38+
fullWidth
39+
className={`mb-2 ${match ? 'bg-primary' : ''}`}
40+
isPressable
41+
onPress={() => navigate('/profiles')}
42+
>
43+
<CardBody className="pb-1">
44+
<div className="flex justify-between h-[32px]">
45+
<h3
46+
className={`select-none text-ellipsis whitespace-nowrap overflow-hidden text-md font-bold leading-[32px] ${match ? 'text-white' : 'text-foreground'} `}
5947
>
60-
<CgLoadbarDoc className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`} />
61-
</Button>
62-
{info.type === 'remote' && (
48+
{info?.name}
49+
</h3>
50+
<div className="flex">
6351
<Button
6452
isIconOnly
6553
size="sm"
66-
disabled={updating}
54+
title="查看当前运行时配置"
6755
variant="light"
6856
color="default"
6957
onPress={() => {
70-
setUpdating(true)
71-
addProfileItem(info).finally(() => {
72-
setUpdating(false)
73-
})
58+
setShowRuntimeConfig(true)
7459
}}
7560
>
76-
<IoMdRefresh
77-
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'} ${updating ? 'animate-spin' : ''}`}
61+
<CgLoadbarDoc
62+
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'}`}
7863
/>
7964
</Button>
80-
)}
65+
{info.type === 'remote' && (
66+
<Button
67+
isIconOnly
68+
size="sm"
69+
disabled={updating}
70+
variant="light"
71+
color="default"
72+
onPress={() => {
73+
setUpdating(true)
74+
addProfileItem(info).finally(() => {
75+
setUpdating(false)
76+
})
77+
}}
78+
>
79+
<IoMdRefresh
80+
className={`text-[24px] ${match ? 'text-white' : 'text-foreground'} ${updating ? 'animate-spin' : ''}`}
81+
/>
82+
</Button>
83+
)}
84+
</div>
8185
</div>
82-
</div>
83-
{info.type === 'remote' && (
84-
<div
85-
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'} `}
86-
>
87-
<small>{extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}</small>
88-
<small>{dayjs(info.updated).fromNow()}</small>
89-
</div>
90-
)}
91-
{info.type === 'local' && (
92-
<div
93-
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'}`}
94-
>
95-
<Chip
96-
size="sm"
97-
variant="bordered"
98-
className={`${match ? 'text-white border-white' : 'border-primary text-primary'}`}
86+
{info.type === 'remote' && (
87+
<div
88+
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'} `}
9989
>
100-
本地
101-
</Chip>
102-
</div>
103-
)}
104-
</CardBody>
105-
<CardFooter className="pt-0">
106-
{extra && (
107-
<Progress
108-
className="w-full"
109-
classNames={{ indicator: match ? 'bg-white' : 'bg-foreground', label: 'select-none' }}
110-
value={calcPercent(extra?.upload, extra?.download, extra?.total)}
111-
/>
112-
)}
113-
</CardFooter>
114-
</Card>
90+
<small>{extra ? `${calcTraffic(usage)}/${calcTraffic(total)}` : undefined}</small>
91+
<small>{dayjs(info.updated).fromNow()}</small>
92+
</div>
93+
)}
94+
{info.type === 'local' && (
95+
<div
96+
className={`mt-2 flex select-none justify-between ${match ? 'text-white' : 'text-foreground'}`}
97+
>
98+
<Chip
99+
size="sm"
100+
variant="bordered"
101+
className={`${match ? 'text-white border-white' : 'border-primary text-primary'}`}
102+
>
103+
本地
104+
</Chip>
105+
</div>
106+
)}
107+
</CardBody>
108+
<CardFooter className="pt-0">
109+
{extra && (
110+
<Progress
111+
className="w-full"
112+
classNames={{ indicator: match ? 'bg-white' : 'bg-foreground', label: 'select-none' }}
113+
value={calcPercent(extra?.upload, extra?.download, extra?.total)}
114+
/>
115+
)}
116+
</CardFooter>
117+
</Card>
118+
</>
115119
)
116120
}
117121

src/renderer/src/components/sysproxy/pac-editor-modal.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ const PacEditorViewer: React.FC<Props> = (props) => {
2424
}
2525

2626
return (
27-
<Modal size="5xl" hideCloseButton isOpen={true} onOpenChange={onCancel} scrollBehavior="inside">
27+
<Modal
28+
backdrop="blur"
29+
size="5xl"
30+
hideCloseButton
31+
isOpen={true}
32+
onOpenChange={onCancel}
33+
scrollBehavior="inside"
34+
>
2835
<ModalContent className="h-full w-[calc(100%-100px)]">
2936
<ModalHeader className="flex">编辑PAC脚本</ModalHeader>
3037
<ModalBody className="h-full">

0 commit comments

Comments
 (0)