import { useEffect, useState } from 'react'; import { Form, Radio, Switch, Input, Button, Space, message, Tooltip } from 'antd'; import { QuestionCircleOutlined } from '@ant-design/icons'; 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 useInit from '@/hooks/useInit'; import { DISABLE_AUTO_COMPLETE, chatRoot } from '@/utils'; const AutoUpdateLabel = () => { return ( Auto Update
Auto Update Policy
Prompt: prompt to install
Silent: install silently
{/*Disable: disable auto update
*/} )}>
) } const OriginLabel = ({ url }: { url: string }) => { return ( Switch Origin ) } const Dalle2SearchLabel = () => { return ( DALL·E 2 Search {' '}
Generate images according to the content: Select the ChatGPT content with the mouse, no more than 400 characters. the DALL·E 2 button appears, and click to jump (Note: because the search content filled by the script cannot trigger the event directly, you need to enter a space in the input box to make the button clickable).
The application is built using Tauri, and due to its security restrictions, some of the action buttons will not work, so we recommend going to your browser.
)}>
) } const GlobalShortcutLabel = () => { return (
Global Shortcut {' '}
Shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q
If empty, the shortcut is disabled.
https://tauri.app/v1/api/js/globalshortcut
)}> ) } export default function General() { const [form] = Form.useForm(); const [jsonPath, setJsonPath] = useState(''); const [platformInfo, setPlatform] = useState(''); const [chatConf, setChatConf] = useState(null); useInit(async () => { setJsonPath(await path.join(await chatRoot(), 'chat.conf.json')); setPlatform(await platform()); const chatData = await invoke('get_chat_conf'); setChatConf(chatData); }); useEffect(() => { form.setFieldsValue(clone(chatConf)); }, [chatConf]) const onCancel = () => { form.setFieldsValue(chatConf); }; const onReset = async () => { const chatData = await invoke('reset_chat_conf'); setChatConf(chatData); const isOk = await ask(`Configuration reset successfully, whether to restart?`, { title: 'ChatGPT Preferences' }); if (isOk) { relaunch(); return; } message.success('Configuration reset successfully'); }; const onFinish = async (values: any) => { if (!isEqual(omit(chatConf, ['default_origin']), values)) { await invoke('form_confirm', { data: values, label: 'main' }); const isOk = await ask(`Configuration saved successfully, whether to restart?`, { title: 'ChatGPT Preferences' }); if (isOk) { relaunch(); return; } message.success('Configuration saved successfully'); } }; return ( <>
{platformInfo === 'darwin' && ( )} } name="dalle2_search" valuePropName="checked"> Light Dark {["darwin", "windows"].includes(platformInfo) && ( System )} } name="auto_update"> Prompt Silent {/*Disable*/} } name="global_shortcut"> } name="origin">
) }