diff --git a/src/main/utils/cmds.ts b/src/main/utils/cmds.ts index 1295151b..e7117f08 100644 --- a/src/main/utils/cmds.ts +++ b/src/main/utils/cmds.ts @@ -1,4 +1,4 @@ -import { ipcMain } from 'electron' +import { app, ipcMain } from 'electron' import { mihomoChangeProxy, mihomoConfig, @@ -32,12 +32,12 @@ export function registerIpcMainHandlers(): void { ipcMain.handle('mihomoConfig', mihomoConfig) ipcMain.handle('mihomoConnections', mihomoConnections) ipcMain.handle('mihomoRules', mihomoRules) - ipcMain.handle('mihomoProxies', () => mihomoProxies()) + ipcMain.handle('mihomoProxies', mihomoProxies) ipcMain.handle('mihomoChangeProxy', (_e, group, proxy) => mihomoChangeProxy(group, proxy)) ipcMain.handle('mihomoProxyDelay', (_e, proxy, url) => mihomoProxyDelay(proxy, url)) ipcMain.handle('startMihomoLogs', startMihomoLogs) - ipcMain.handle('stopMihomoLogs', () => stopMihomoLogs()) - ipcMain.handle('patchMihomoConfig', async (_e, patch) => await patchMihomoConfig(patch)) + ipcMain.handle('stopMihomoLogs', stopMihomoLogs) + ipcMain.handle('patchMihomoConfig', (_e, patch) => patchMihomoConfig(patch)) ipcMain.handle('checkAutoRun', checkAutoRun) ipcMain.handle('enableAutoRun', enableAutoRun) ipcMain.handle('disableAutoRun', disableAutoRun) @@ -51,6 +51,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', () => restartCore()) + ipcMain.handle('restartCore', restartCore) ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable)) + ipcMain.handle('quitApp', () => app.quit()) } diff --git a/src/renderer/src/components/base/base-setting-item.tsx b/src/renderer/src/components/base/base-setting-item.tsx index e6e93d0c..ae212ca7 100644 --- a/src/renderer/src/components/base/base-setting-item.tsx +++ b/src/renderer/src/components/base/base-setting-item.tsx @@ -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' interface Props { + onPress?: () => void title: React.ReactNode actions?: React.ReactNode children?: React.ReactNode @@ -9,20 +11,33 @@ interface Props { } const SettingItem: React.FC = (props) => { - const { divider = false } = props - - return ( - <> -
-
-

{props.title}

-
{props.actions}
+ const { title, actions, children, divider = false, onPress } = props + if (onPress) { + return ( + <> +
+

{title}

+ +
+ {divider && } + + ) + } else { + return ( + <> +
+
+

{title}

+
{actions}
+
+ {children}
- {props.children} -
- {divider && } - - ) + {divider && } + + ) + } } export default SettingItem diff --git a/src/renderer/src/pages/mihomo.tsx b/src/renderer/src/pages/mihomo.tsx index 50d880de..ececba40 100644 --- a/src/renderer/src/pages/mihomo.tsx +++ b/src/renderer/src/pages/mihomo.tsx @@ -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 + const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() + const { + ipv6, + 'log-level': level = 'info', + 'allow-lan': lan, + 'mixed-port': mixedPort = 7890 + } = controledMihomoConfig || {} + + const onChange = async (patch: Partial): Promise => { + await patchControledMihomoConfig(patch) + await patchMihomoConfig(patch) + } + + return ( + + + + { + onChange({ 'mixed-port': parseInt(v) }) + }} + /> + + + { + onChange({ ipv6: v }) + }} + /> + + + { + onChange({ 'allow-lan': v }) + }} + /> + + + + + + + ) } export default Mihomo diff --git a/src/renderer/src/pages/settings.tsx b/src/renderer/src/pages/settings.tsx index af6e15ae..5f7b2659 100644 --- a/src/renderer/src/pages/settings.tsx +++ b/src/renderer/src/pages/settings.tsx @@ -3,7 +3,7 @@ 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 { 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 useSWR from 'swr' @@ -83,6 +83,9 @@ const Settings: React.FC = () => { > + + + ) } diff --git a/src/renderer/src/utils/ipc.ts b/src/renderer/src/utils/ipc.ts index f9aa14a0..cb350484 100644 --- a/src/renderer/src/utils/ipc.ts +++ b/src/renderer/src/utils/ipc.ts @@ -97,3 +97,7 @@ export async function restartCore(): Promise { export async function triggerSysProxy(enable: boolean): Promise { return await window.electron.ipcRenderer.invoke('triggerSysProxy', enable) } + +export async function quitApp(): Promise { + return await window.electron.ipcRenderer.invoke('quitApp') +}