mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
some settings
This commit is contained in:
parent
0fc43b339d
commit
f2e9d50a1f
@ -1,4 +1,4 @@
|
|||||||
import { ipcMain } from 'electron'
|
import { app, ipcMain } from 'electron'
|
||||||
import {
|
import {
|
||||||
mihomoChangeProxy,
|
mihomoChangeProxy,
|
||||||
mihomoConfig,
|
mihomoConfig,
|
||||||
@ -32,12 +32,12 @@ export function registerIpcMainHandlers(): void {
|
|||||||
ipcMain.handle('mihomoConfig', mihomoConfig)
|
ipcMain.handle('mihomoConfig', mihomoConfig)
|
||||||
ipcMain.handle('mihomoConnections', mihomoConnections)
|
ipcMain.handle('mihomoConnections', mihomoConnections)
|
||||||
ipcMain.handle('mihomoRules', mihomoRules)
|
ipcMain.handle('mihomoRules', mihomoRules)
|
||||||
ipcMain.handle('mihomoProxies', () => mihomoProxies())
|
ipcMain.handle('mihomoProxies', mihomoProxies)
|
||||||
ipcMain.handle('mihomoChangeProxy', (_e, group, proxy) => mihomoChangeProxy(group, proxy))
|
ipcMain.handle('mihomoChangeProxy', (_e, group, proxy) => mihomoChangeProxy(group, proxy))
|
||||||
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) => mihomoProxyDelay(proxy, url))
|
ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) => mihomoProxyDelay(proxy, url))
|
||||||
ipcMain.handle('startMihomoLogs', startMihomoLogs)
|
ipcMain.handle('startMihomoLogs', startMihomoLogs)
|
||||||
ipcMain.handle('stopMihomoLogs', () => stopMihomoLogs())
|
ipcMain.handle('stopMihomoLogs', stopMihomoLogs)
|
||||||
ipcMain.handle('patchMihomoConfig', async (_e, patch) => await patchMihomoConfig(patch))
|
ipcMain.handle('patchMihomoConfig', (_e, patch) => patchMihomoConfig(patch))
|
||||||
ipcMain.handle('checkAutoRun', checkAutoRun)
|
ipcMain.handle('checkAutoRun', checkAutoRun)
|
||||||
ipcMain.handle('enableAutoRun', enableAutoRun)
|
ipcMain.handle('enableAutoRun', enableAutoRun)
|
||||||
ipcMain.handle('disableAutoRun', disableAutoRun)
|
ipcMain.handle('disableAutoRun', disableAutoRun)
|
||||||
@ -51,6 +51,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', () => restartCore())
|
ipcMain.handle('restartCore', restartCore)
|
||||||
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
||||||
|
ipcMain.handle('quitApp', () => app.quit())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { Divider } from '@nextui-org/react'
|
import { Button, Divider } from '@nextui-org/react'
|
||||||
|
import { FaChevronRight } from 'react-icons/fa'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
onPress?: () => void
|
||||||
title: React.ReactNode
|
title: React.ReactNode
|
||||||
actions?: React.ReactNode
|
actions?: React.ReactNode
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
@ -9,20 +11,33 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SettingItem: React.FC<Props> = (props) => {
|
const SettingItem: React.FC<Props> = (props) => {
|
||||||
const { divider = false } = props
|
const { title, actions, children, divider = false, onPress } = props
|
||||||
|
if (onPress) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="h-[32px] w-full flex justify-between">
|
<div className="p-0 m-0 h-[32px] w-full flex justify-between">
|
||||||
<div className="h-full flex items-center">
|
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
|
||||||
<h4 className="h-full select-none text-md leading-[32px]">{props.title}</h4>
|
<Button size="sm" onPress={onPress}>
|
||||||
<div>{props.actions}</div>
|
<FaChevronRight />
|
||||||
</div>
|
</Button>
|
||||||
{props.children}
|
|
||||||
</div>
|
</div>
|
||||||
{divider && <Divider className="my-2" />}
|
{divider && <Divider className="my-2" />}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="h-[32px] w-full flex justify-between">
|
||||||
|
<div className="h-full flex items-center">
|
||||||
|
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
|
||||||
|
<div>{actions}</div>
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
{divider && <Divider className="my-2" />}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SettingItem
|
export default SettingItem
|
||||||
|
|||||||
@ -1,7 +1,78 @@
|
|||||||
|
import { Input, Select, SelectItem, Switch } from '@nextui-org/react'
|
||||||
import BasePage from '@renderer/components/base/base-page'
|
import BasePage from '@renderer/components/base/base-page'
|
||||||
|
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||||
|
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||||
|
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
|
||||||
|
import { patchMihomoConfig } from '@renderer/utils/ipc'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
const Mihomo: React.FC = () => {
|
const Mihomo: React.FC = () => {
|
||||||
return <BasePage title="内核设置"></BasePage>
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||||
|
const {
|
||||||
|
ipv6,
|
||||||
|
'log-level': level = 'info',
|
||||||
|
'allow-lan': lan,
|
||||||
|
'mixed-port': mixedPort = 7890
|
||||||
|
} = controledMihomoConfig || {}
|
||||||
|
|
||||||
|
const onChange = async (patch: Partial<IMihomoConfig>): Promise<void> => {
|
||||||
|
await patchControledMihomoConfig(patch)
|
||||||
|
await patchMihomoConfig(patch)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BasePage title="内核设置">
|
||||||
|
<SettingCard>
|
||||||
|
<SettingItem title="混合端口" divider>
|
||||||
|
<Input
|
||||||
|
size="sm"
|
||||||
|
type="number"
|
||||||
|
className="w-[100px]"
|
||||||
|
value={mixedPort.toString()}
|
||||||
|
max={65535}
|
||||||
|
min={0}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
onChange({ 'mixed-port': parseInt(v) })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem title="IPv6" divider>
|
||||||
|
<Switch
|
||||||
|
size="sm"
|
||||||
|
isSelected={ipv6}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
onChange({ ipv6: v })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem title="允许局域网连接" divider>
|
||||||
|
<Switch
|
||||||
|
size="sm"
|
||||||
|
isSelected={lan}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
onChange({ 'allow-lan': v })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem title="日志等级">
|
||||||
|
<Select
|
||||||
|
className="w-[100px]"
|
||||||
|
size="sm"
|
||||||
|
selectedKeys={new Set([level])}
|
||||||
|
onSelectionChange={(v) => {
|
||||||
|
onChange({ 'log-level': v.currentKey as LogLevel })
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectItem key="silent">静默</SelectItem>
|
||||||
|
<SelectItem key="info">信息</SelectItem>
|
||||||
|
<SelectItem key="warning">警告</SelectItem>
|
||||||
|
<SelectItem key="error">错误</SelectItem>
|
||||||
|
<SelectItem key="debug">调试</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</SettingItem>
|
||||||
|
</SettingCard>
|
||||||
|
</BasePage>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Mihomo
|
export default Mihomo
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import BasePage from '@renderer/components/base/base-page'
|
|||||||
import SettingCard from '@renderer/components/base/base-setting-card'
|
import SettingCard from '@renderer/components/base/base-setting-card'
|
||||||
import SettingItem from '@renderer/components/base/base-setting-item'
|
import SettingItem from '@renderer/components/base/base-setting-item'
|
||||||
import { useAppConfig } from '@renderer/hooks/use-config'
|
import { useAppConfig } from '@renderer/hooks/use-config'
|
||||||
import { checkAutoRun, enableAutoRun, disableAutoRun } from '@renderer/utils/ipc'
|
import { checkAutoRun, enableAutoRun, disableAutoRun, quitApp } from '@renderer/utils/ipc'
|
||||||
import { IoLogoGithub } from 'react-icons/io5'
|
import { IoLogoGithub } from 'react-icons/io5'
|
||||||
|
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
@ -83,6 +83,9 @@ const Settings: React.FC = () => {
|
|||||||
></Input>
|
></Input>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingCard>
|
</SettingCard>
|
||||||
|
<SettingCard>
|
||||||
|
<SettingItem title="退出应用" onPress={quitApp} />
|
||||||
|
</SettingCard>
|
||||||
</BasePage>
|
</BasePage>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,3 +97,7 @@ export async function restartCore(): Promise<void> {
|
|||||||
export async function triggerSysProxy(enable: boolean): Promise<void> {
|
export async function triggerSysProxy(enable: boolean): Promise<void> {
|
||||||
return await window.electron.ipcRenderer.invoke('triggerSysProxy', enable)
|
return await window.electron.ipcRenderer.invoke('triggerSysProxy', enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function quitApp(): Promise<void> {
|
||||||
|
return await window.electron.ipcRenderer.invoke('quitApp')
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user