@@ -12,8 +12,12 @@ struct TokenSettingView: View {
1212
1313 @Binding var isAddPresented : Bool
1414 @StateObject var chatModel : AIChatModel
15- @State private var text : String = " "
16- @State private var error : String = " "
15+ @State private var sessionToken : String = " "
16+ @State private var cfClearance : String = " "
17+ @State private var userAgent : String = " "
18+ @State private var sError : String = " "
19+ @State private var cError : String = " "
20+ @State private var uError : String = " "
1721
1822 private let appVersion = Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String
1923 private let appSubVersion = Bundle . main. infoDictionary ? [ " CFBundleVersion " ] as? String
@@ -39,32 +43,77 @@ struct TokenSettingView: View {
3943
4044 VStack ( alignment: . leading) {
4145 Text ( " Session Token: " )
42- MultilineTextField ( " 请输入 Session Token " , text: $text, maxHeight: 300 , onCommit: {
43- #if DEBUG
44- print ( " Final text: \( text) " )
45- #endif
46- } )
47- . overlay ( RoundedRectangle ( cornerRadius: 5 )
48- . stroke ( Color . secondary) )
46+ let sTextField = TextField ( " 请输入 session_token " , text: $sessionToken)
47+ . frame ( height: 40 )
48+ . overlay ( RoundedRectangle ( cornerRadius: 5 )
49+ . stroke ( Color ( . tertiaryLabel) ) )
4950
50- if error. count > 0 && text. count == 0 {
51- Text ( error)
51+ if #available( iOS 15 . 0 , * ) {
52+ sTextField. submitLabel ( . done)
53+ }
54+
55+ if sError. count > 0 && sessionToken. isEmpty {
56+ Text ( sError)
57+ . foregroundColor ( . red)
58+ }
59+
60+ Text ( " Cf Clearance: " )
61+ . padding ( . top, 15 )
62+ let cTextField = TextField ( " 请输入 cf_clearance " , text: $cfClearance)
63+ . frame ( height: 40 )
64+ . overlay ( RoundedRectangle ( cornerRadius: 5 )
65+ . stroke ( Color . secondary) )
66+
67+ if #available( iOS 15 . 0 , * ) {
68+ cTextField. submitLabel ( . done)
69+ }
70+
71+ if cError. count > 0 && cfClearance. isEmpty {
72+ Text ( cError)
73+ . foregroundColor ( . red)
74+ }
75+
76+ Text ( " User Agent: " )
77+ . padding ( . top, 15 )
78+ let uTextField = TextField ( " 请输入 user_agent " , text: $userAgent)
79+ . frame ( height: 40 )
80+ . overlay ( RoundedRectangle ( cornerRadius: 5 )
81+ . stroke ( Color . secondary) )
82+
83+ if #available( iOS 15 . 0 , * ) {
84+ uTextField. submitLabel ( . done)
85+ }
86+
87+ if uError. count > 0 && userAgent. isEmpty {
88+ Text ( uError)
5289 . foregroundColor ( . red)
90+ . padding ( . bottom, 10 )
5391 }
5492 }
5593 . padding ( [ . leading, . trailing] , 20 )
5694
5795 Spacer ( )
5896 Button ( action: {
59- if text. isEmpty {
60- error = " Session Token 不能为空! "
61- } else {
62- UserDefaults . standard. set ( text, forKey: ChatGPTSessionTokenKey)
63- isAddPresented = false
64- chatModel. isRefreshSession = true
97+ guard !sessionToken. isEmpty else {
98+ sError = " Session Token 不能为空! "
99+ return
100+ }
101+ guard !cfClearance. isEmpty else {
102+ cError = " Cf Clearance 不能为空! "
103+ return
65104 }
105+ guard !userAgent. isEmpty else {
106+ uError = " User Agent 不能为空! "
107+ return
108+ }
109+
110+ UserDefaults . standard. set ( sessionToken, forKey: ChatGPTSessionTokenKey)
111+ UserDefaults . standard. set ( cfClearance, forKey: ChatGPTCfClearanceKey)
112+ UserDefaults . standard. set ( userAgent, forKey: ChatGPTUserAgentKey)
113+ isAddPresented = false
114+ chatModel. isRefreshSession = true
66115 } ) {
67- Text ( " 确认 " )
116+ Text ( " 保存 " )
68117 . font ( . title3)
69118 . foregroundColor ( . blue)
70119 . padding ( [ . leading, . trailing] , 20 )
@@ -83,7 +132,7 @@ struct TokenSettingView: View {
83132 . font ( . footnote)
84133 . foregroundColor ( . secondary)
85134 . multilineTextAlignment ( . center)
86- . padding ( . bottom, 5 )
135+ . padding ( . bottom, 25 )
87136 }
88137 }
89138}
0 commit comments