1
1
import { useEffect , useState } from 'react' ;
2
2
import { Form , Radio , Switch , Input , Button , Space , message , Tooltip } from 'antd' ;
3
3
import { QuestionCircleOutlined } from '@ant-design/icons' ;
4
- import { invoke , shell , path } from '@tauri-apps/api' ;
4
+ import { invoke } from '@tauri-apps/api' ;
5
5
import { platform } from '@tauri-apps/api/os' ;
6
6
import { ask } from '@tauri-apps/api/dialog' ;
7
7
import { relaunch } from '@tauri-apps/api/process' ;
8
8
import { clone , omit , isEqual } from 'lodash' ;
9
9
10
- import useInit from '@/hooks/useInit' ;
11
- import { DISABLE_AUTO_COMPLETE , chatRoot } from '@/utils' ;
10
+ import { DISABLE_AUTO_COMPLETE } from '@/utils' ;
12
11
13
12
const OriginLabel = ( { url } : { url : string } ) => {
14
13
return (
15
14
< span >
16
- Switch Origin < Tooltip title = { `Default: ${ url } ` } > < QuestionCircleOutlined style = { { color : '#1677ff' } } /> </ Tooltip >
15
+ Switch Origin < Tooltip title = { `Default: ${ url } ` } > < QuestionCircleOutlined /> </ Tooltip >
17
16
</ span >
18
17
)
19
18
}
@@ -30,25 +29,26 @@ const GlobalShortcut = () => {
30
29
< a href = "https://tauri.app/v1/api/js/globalshortcut" target = "_blank" > https://tauri.app/v1/api/js/globalshortcut</ a >
31
30
</ div >
32
31
) } >
33
- < QuestionCircleOutlined style = { { color : '#1677ff' } } />
32
+ < QuestionCircleOutlined />
34
33
</ Tooltip >
35
34
</ div >
36
35
)
37
36
}
38
37
39
38
export default function General ( ) {
40
39
const [ form ] = Form . useForm ( ) ;
41
- const [ jsonPath , setJsonPath ] = useState ( '' ) ;
42
40
const [ platformInfo , setPlatform ] = useState < string > ( '' ) ;
43
41
const [ chatConf , setChatConf ] = useState < any > ( null ) ;
44
42
45
- useInit ( async ( ) => {
46
- setJsonPath ( await path . join ( await chatRoot ( ) , 'chat.conf.json' ) ) ;
47
-
43
+ const init = async ( ) => {
48
44
setPlatform ( await platform ( ) ) ;
49
45
const chatData = await invoke ( 'get_chat_conf' ) ;
50
46
setChatConf ( chatData ) ;
51
- } ) ;
47
+ }
48
+
49
+ useEffect ( ( ) => {
50
+ init ( ) ;
51
+ } , [ ] )
52
52
53
53
useEffect ( ( ) => {
54
54
form . setFieldsValue ( clone ( chatConf ) ) ;
@@ -73,54 +73,47 @@ export default function General() {
73
73
} ;
74
74
75
75
return (
76
- < >
77
- < div className = "chat-table-tip" >
78
- < div className = "chat-sync-path" >
79
- < div > PATH: < a onClick = { ( ) => shell . open ( jsonPath ) } title = { jsonPath } > { jsonPath } </ a > </ div >
80
- </ div >
81
- </ div >
82
- < Form
83
- form = { form }
84
- style = { { maxWidth : 500 } }
85
- onFinish = { onFinish }
86
- labelCol = { { span : 8 } }
87
- wrapperCol = { { span : 15 , offset : 1 } }
88
- >
89
- < Form . Item label = "Theme" name = "theme" >
90
- < Radio . Group >
91
- < Radio value = "Light" > Light</ Radio >
92
- < Radio value = "Dark" > Dark</ Radio >
93
- </ Radio . Group >
94
- </ Form . Item >
95
- < Form . Item label = "Stay On Top" name = "stay_on_top" valuePropName = "checked" >
76
+ < Form
77
+ form = { form }
78
+ style = { { maxWidth : 500 } }
79
+ onFinish = { onFinish }
80
+ labelCol = { { span : 8 } }
81
+ wrapperCol = { { span : 15 , offset : 1 } }
82
+ >
83
+ < Form . Item label = "Theme" name = "theme" >
84
+ < Radio . Group >
85
+ < Radio value = "Light" > Light</ Radio >
86
+ < Radio value = "Dark" > Dark</ Radio >
87
+ </ Radio . Group >
88
+ </ Form . Item >
89
+ < Form . Item label = "Stay On Top" name = "stay_on_top" valuePropName = "checked" >
90
+ < Switch />
91
+ </ Form . Item >
92
+ < Form . Item label = { < GlobalShortcut /> } name = "global_shortcut" >
93
+ < Input placeholder = "CmdOrCtrl+Shift+O" { ...DISABLE_AUTO_COMPLETE } />
94
+ </ Form . Item >
95
+ { platformInfo === 'darwin' && (
96
+ < Form . Item label = "Titlebar" name = "titlebar" valuePropName = "checked" >
96
97
< Switch />
97
98
</ Form . Item >
98
- < Form . Item label = { < GlobalShortcut /> } name = "global_shortcut" >
99
- < Input placeholder = "CmdOrCtrl+Shift+O" { ...DISABLE_AUTO_COMPLETE } />
100
- </ Form . Item >
101
- { platformInfo === 'darwin' && (
102
- < Form . Item label = "Titlebar" name = "titlebar" valuePropName = "checked" >
103
- < Switch />
104
- </ Form . Item >
105
- ) }
106
- < Form . Item label = { < OriginLabel url = { chatConf ?. default_origin } /> } name = "origin" >
107
- < Input placeholder = "https://chat.openai.com" { ...DISABLE_AUTO_COMPLETE } />
108
- </ Form . Item >
109
- < Form . Item label = "User Agent (Window)" name = "ua_window" >
110
- < Input . TextArea autoSize = { { minRows : 4 , maxRows : 4 } } { ...DISABLE_AUTO_COMPLETE } placeholder = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
111
- </ Form . Item >
112
- < Form . Item label = "User Agent (SystemTray)" name = "ua_tray" >
113
- < Input . TextArea autoSize = { { minRows : 4 , maxRows : 4 } } { ...DISABLE_AUTO_COMPLETE } placeholder = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
114
- </ Form . Item >
115
- < Form . Item >
116
- < Space size = { 20 } >
117
- < Button onClick = { onCancel } > Cancel</ Button >
118
- < Button type = "primary" htmlType = "submit" >
119
- Submit
120
- </ Button >
121
- </ Space >
122
- </ Form . Item >
123
- </ Form >
124
- </ >
99
+ ) }
100
+ < Form . Item label = { < OriginLabel url = { chatConf ?. default_origin } /> } name = "origin" >
101
+ < Input placeholder = "https://chat.openai.com" { ...DISABLE_AUTO_COMPLETE } />
102
+ </ Form . Item >
103
+ < Form . Item label = "User Agent (Window)" name = "ua_window" >
104
+ < Input . TextArea autoSize = { { minRows : 4 , maxRows : 4 } } { ...DISABLE_AUTO_COMPLETE } placeholder = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
105
+ </ Form . Item >
106
+ < Form . Item label = "User Agent (SystemTray)" name = "ua_tray" >
107
+ < Input . TextArea autoSize = { { minRows : 4 , maxRows : 4 } } { ...DISABLE_AUTO_COMPLETE } placeholder = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" />
108
+ </ Form . Item >
109
+ < Form . Item >
110
+ < Space size = { 20 } >
111
+ < Button onClick = { onCancel } > Cancel</ Button >
112
+ < Button type = "primary" htmlType = "submit" >
113
+ Submit
114
+ </ Button >
115
+ </ Space >
116
+ </ Form . Item >
117
+ </ Form >
125
118
)
126
119
}
0 commit comments