diff --git a/src/view/General.tsx b/src/view/General.tsx index 20f29b9..96ea35c 100644 --- a/src/view/General.tsx +++ b/src/view/General.tsx @@ -1,18 +1,19 @@ import { useEffect, useState } from 'react'; import { Form, Radio, Switch, Input, Button, Space, message, Tooltip } from 'antd'; import { QuestionCircleOutlined } from '@ant-design/icons'; -import { invoke } from '@tauri-apps/api'; +import { invoke, shell, path } from '@tauri-apps/api'; import { platform } from '@tauri-apps/api/os'; import { ask } from '@tauri-apps/api/dialog'; import { relaunch } from '@tauri-apps/api/process'; import { clone, omit, isEqual } from 'lodash'; -import { DISABLE_AUTO_COMPLETE } from '@/utils'; +import useInit from '@/hooks/useInit'; +import { DISABLE_AUTO_COMPLETE, chatRoot } from '@/utils'; const OriginLabel = ({ url }: { url: string }) => { return ( - Switch Origin + Switch Origin ) } @@ -29,7 +30,7 @@ const GlobalShortcut = () => { https://tauri.app/v1/api/js/globalshortcut )}> - + ) @@ -37,18 +38,17 @@ const GlobalShortcut = () => { export default function General() { const [form] = Form.useForm(); + const [jsonPath, setJsonPath] = useState(''); const [platformInfo, setPlatform] = useState(''); const [chatConf, setChatConf] = useState(null); - const init = async () => { + useInit(async () => { + setJsonPath(await path.join(await chatRoot(), 'chat.conf.json')); + setPlatform(await platform()); const chatData = await invoke('get_chat_conf'); setChatConf(chatData); - } - - useEffect(() => { - init(); - }, []) + }); useEffect(() => { form.setFieldsValue(clone(chatConf)); @@ -73,47 +73,54 @@ export default function General() { }; return ( -
- - - Light - Dark - - - - - - } name="global_shortcut"> - - - {platformInfo === 'darwin' && ( - + <> + + + + + Light + Dark + + + - )} - } name="origin"> - - - - - - - - - - - - - - - + } name="global_shortcut"> + + + {platformInfo === 'darwin' && ( + + + + )} + } name="origin"> + + + + + + + + + + + + + + + + ) } \ No newline at end of file