-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pompurin404
committed
Aug 3, 2024
1 parent
db1766b
commit ba6f8bd
Showing
5 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
import { Divider } from '@nextui-org/react' | ||
import { Button, Divider } from '@nextui-org/react' | ||
import { FaChevronRight } from 'react-icons/fa' | ||
import React from 'react' | ||
|
||
interface Props { | ||
onPress?: () => void | ||
title: React.ReactNode | ||
actions?: React.ReactNode | ||
children?: React.ReactNode | ||
divider?: boolean | ||
} | ||
|
||
const SettingItem: React.FC<Props> = (props) => { | ||
const { divider = false } = props | ||
|
||
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]">{props.title}</h4> | ||
<div>{props.actions}</div> | ||
const { title, actions, children, divider = false, onPress } = props | ||
if (onPress) { | ||
return ( | ||
<> | ||
<div className="p-0 m-0 h-[32px] w-full flex justify-between"> | ||
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4> | ||
<Button size="sm" onPress={onPress}> | ||
<FaChevronRight /> | ||
</Button> | ||
</div> | ||
{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> | ||
{props.children} | ||
</div> | ||
{divider && <Divider className="my-2" />} | ||
</> | ||
) | ||
{divider && <Divider className="my-2" />} | ||
</> | ||
) | ||
} | ||
} | ||
|
||
export default SettingItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
import { Input, Select, SelectItem, Switch } from '@nextui-org/react' | ||
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 = () => { | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters