From b8757277539546ffcfe60047241dc33b69ed83d9 Mon Sep 17 00:00:00 2001 From: lencx Date: Sun, 22 Jan 2023 11:43:56 +0800 Subject: [PATCH] chore: settings --- src/routes.tsx | 8 +- src/view/General.tsx | 176 ------------------------------- src/view/settings/General.tsx | 82 ++++++++++++++ src/view/settings/MainWindow.tsx | 53 ++++++++++ src/view/settings/TrayWindow.tsx | 16 +++ src/view/settings/index.tsx | 85 +++++++++++++++ 6 files changed, 240 insertions(+), 180 deletions(-) delete mode 100644 src/view/General.tsx create mode 100644 src/view/settings/General.tsx create mode 100644 src/view/settings/MainWindow.tsx create mode 100644 src/view/settings/TrayWindow.tsx create mode 100644 src/view/settings/index.tsx diff --git a/src/routes.tsx b/src/routes.tsx index 5e17488..e38d38a 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -11,7 +11,7 @@ import { } from '@ant-design/icons'; import type { MenuProps } from 'antd'; -import General from '@/view/General'; +import Settings from '@/view/settings'; import Awesome from '@/view/awesome'; import UserCustom from '@/view/model/UserCustom'; import SyncPrompts from '@/view/model/SyncPrompts'; @@ -104,10 +104,10 @@ export const routes: Array = [ }, }, { - path: '/general', - element: , + path: '/settings', + element: , meta: { - label: 'General', + label: 'Settings', icon: , }, }, diff --git a/src/view/General.tsx b/src/view/General.tsx deleted file mode 100644 index 7e709ad..0000000 --- a/src/view/General.tsx +++ /dev/null @@ -1,176 +0,0 @@ -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 { 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 FilePath from '@/components/FilePath'; -import { DISABLE_AUTO_COMPLETE, CHAT_CONF_JSON } 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 PopupSearchLabel = () => { - return ( - - Pop-up 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 [platformInfo, setPlatform] = useState(''); - const [chatConf, setChatConf] = useState(null); - - useInit(async () => { - 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="popup_search" valuePropName="checked"> - - - - - Light - Dark - {["darwin", "windows"].includes(platformInfo) && ( - System - )} - - - } name="auto_update"> - - Prompt - Silent - {/*Disable*/} - - - } name="global_shortcut"> - - - } name="origin"> - - - - - - - - - - - - - - - - -
- - ) -} \ No newline at end of file diff --git a/src/view/settings/General.tsx b/src/view/settings/General.tsx new file mode 100644 index 0000000..9b2189d --- /dev/null +++ b/src/view/settings/General.tsx @@ -0,0 +1,82 @@ +import { useState } from 'react'; +import { Form, Radio, Switch, Input, Tooltip } from 'antd'; +import { QuestionCircleOutlined } from '@ant-design/icons'; +import { platform } from '@tauri-apps/api/os'; + +import useInit from '@/hooks/useInit'; +import { DISABLE_AUTO_COMPLETE } from '@/utils'; + +const AutoUpdateLabel = () => { + return ( + + Auto Update + {' '} + +
Auto Update Policy
+
Prompt: prompt to install
+
Silent: install silently
+ {/*
Disable: disable auto update
*/} + + )}>
+
+ ) +} + +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 [platformInfo, setPlatform] = useState(''); + + useInit(async () => { + setPlatform(await platform()); + }); + + return ( + <> + + + + {platformInfo === 'darwin' && ( + + + + )} + + + Light + Dark + {["darwin", "windows"].includes(platformInfo) && ( + System + )} + + + } name="auto_update"> + + Prompt + Silent + {/*Disable*/} + + + } name="global_shortcut"> + + + + ) +} diff --git a/src/view/settings/MainWindow.tsx b/src/view/settings/MainWindow.tsx new file mode 100644 index 0000000..d5e511e --- /dev/null +++ b/src/view/settings/MainWindow.tsx @@ -0,0 +1,53 @@ +import { useState } from 'react'; +import { Form, Switch, Input, Tooltip } from 'antd'; +import { QuestionCircleOutlined } from '@ant-design/icons'; +import { invoke } from '@tauri-apps/api'; + +import useInit from '@/hooks/useInit'; +import { DISABLE_AUTO_COMPLETE } from '@/utils'; + +const OriginLabel = ({ url }: { url: string }) => { + return ( + + Switch Origin + + ) +} + +const PopupSearchLabel = () => { + return ( + + Pop-up 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.
+ + )}>
+
+ ) +} + +export default function General() { + const [chatConf, setChatConf] = useState(null); + + useInit(async () => { + const chatData = await invoke('get_chat_conf'); + setChatConf(chatData); + }); + + return ( + <> + } name="popup_search" valuePropName="checked"> + + + } name="origin"> + + + + + + + ) +} diff --git a/src/view/settings/TrayWindow.tsx b/src/view/settings/TrayWindow.tsx new file mode 100644 index 0000000..7ee94f1 --- /dev/null +++ b/src/view/settings/TrayWindow.tsx @@ -0,0 +1,16 @@ +import { Form, Switch, Input } from 'antd'; + +import { DISABLE_AUTO_COMPLETE } from '@/utils'; + +export default function General() { + return ( + <> + + + + + + + + ) +} diff --git a/src/view/settings/index.tsx b/src/view/settings/index.tsx new file mode 100644 index 0000000..a6a442a --- /dev/null +++ b/src/view/settings/index.tsx @@ -0,0 +1,85 @@ +import { useEffect, useState } from 'react'; +import { Form, Tabs, Space, Button, message } from 'antd'; +import { invoke, dialog, process } from '@tauri-apps/api'; +import { clone, omit, isEqual } from 'lodash'; + +import useInit from '@/hooks/useInit'; +import FilePath from '@/components/FilePath'; +import { CHAT_CONF_JSON } from '@/utils'; +import General from './General'; +import MainWindow from './MainWindow'; +import TrayWindow from './TrayWindow'; + +export default function Settings() { + const [form] = Form.useForm(); + const [chatConf, setChatConf] = useState(null); + + useInit(async () => { + 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 dialog.ask(`Configuration reset successfully, whether to restart?`, { + title: 'ChatGPT Preferences' + }); + if (isOk) { + process.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 dialog.ask(`Configuration saved successfully, whether to restart?`, { + title: 'ChatGPT Preferences' + }); + if (isOk) { + process.relaunch(); + return; + } + message.success('Configuration saved successfully'); + } + }; + + return ( +
+ +
+ }, + { label: 'Main Window', key: 'main_window', children: }, + { label: 'SystemTray Window', key: 'tray_window', children: }, + ]} + /> + + + + + + + + + +
+ ) +} \ No newline at end of file