@@ -9,10 +9,13 @@ let store = StoreOf<TheApp>(
99)
1010
1111struct ContentView : View {
12- @AppStorage ( \. chatModelId) var chatModelId
13- @AppStorage ( \. installBetaBuild) var installBetaBuild
14- @AppStorage ( \. verboseLog) var verboseLog
12+ final class Settings : ObservableObject {
13+ @AppStorage ( \. chatModelId) var chatModelId
14+ @AppStorage ( \. installBetaBuild) var installBetaBuild
15+ @AppStorage ( \. verboseLog) var verboseLog
16+ }
1517
18+ @StateObject var settings = Settings ( )
1619 @State var isEditingCustomModel : Bool = false
1720
1821 @Environment ( \. updateChecker) var updateChecker
@@ -24,7 +27,7 @@ struct ContentView: View {
2427 Form {
2528 HStack {
2629 ExistedChatModelPicker ( )
27- if CustomModelType ( rawValue: chatModelId) != nil {
30+ if CustomModelType ( rawValue: settings . chatModelId) != nil {
2831 Button ( " Edit Model " ) {
2932 isEditingCustomModel = true
3033 }
@@ -41,7 +44,7 @@ struct ContentView: View {
4144 ) ) {
4245 Text ( " Automatically Check for Update " )
4346 }
44-
47+
4548 Button ( action: {
4649 updateChecker. checkForUpdates ( )
4750 } ) {
@@ -51,9 +54,9 @@ struct ContentView: View {
5154 }
5255 }
5356 }
54-
55- Toggle ( " Install Beta Build " , isOn: $installBetaBuild)
56- Toggle ( " Verbose Log (Logs to Console.app) " , isOn: $verboseLog)
57+
58+ Toggle ( " Install Beta Build " , isOn: settings . $installBetaBuild)
59+ Toggle ( " Verbose Log (Logs to Console.app) " , isOn: settings . $verboseLog)
5760 }
5861 }
5962 . formStyle ( . grouped)
@@ -62,7 +65,7 @@ struct ContentView: View {
6265 . padding ( . horizontal, 24 )
6366 }
6467 . sheet ( isPresented: $isEditingCustomModel) {
65- if let type = CustomModelType ( rawValue: chatModelId) {
68+ if let type = CustomModelType ( rawValue: settings . chatModelId) {
6669 switch type {
6770 case . chatModel:
6871 ChatModelEditView ( store: store. scope (
@@ -93,22 +96,26 @@ struct ContentView: View {
9396}
9497
9598struct ExistedChatModelPicker : View {
96- @AppStorage ( \. chatModelsFromCopilotForXcode) var chatModels : [ ChatModel ]
97- @AppStorage ( \. chatModelId) var chatModelId : String
99+ final class Settings : ObservableObject {
100+ @AppStorage ( \. chatModelsFromCopilotForXcode) var chatModels : [ ChatModel ]
101+ @AppStorage ( \. chatModelId) var chatModelId : String
102+ }
103+
104+ @StateObject var settings = Settings ( )
98105
99106 var body : some View {
100107 let unknownId : String ? =
101- if !chatModels. contains ( where: { $0. id == chatModelId } ) ,
102- !chatModelId. isEmpty,
103- CustomModelType ( rawValue: chatModelId) == nil
108+ if !settings . chatModels. contains ( where: { $0. id == settings . chatModelId } ) ,
109+ !settings . chatModelId. isEmpty,
110+ CustomModelType ( rawValue: settings . chatModelId) == nil
104111 {
105- chatModelId
112+ settings . chatModelId
106113 } else {
107114 nil
108115 }
109116
110117 Picker (
111- selection: $chatModelId,
118+ selection: settings . $chatModelId,
112119 label: Text ( " Model " ) ,
113120 content: {
114121 if let unknownId {
@@ -126,7 +133,7 @@ struct ExistedChatModelPicker: View {
126133 }
127134 }
128135
129- ForEach ( chatModels, id: \. id) { chatModel in
136+ ForEach ( settings . chatModels, id: \. id) { chatModel in
130137 Text ( chatModel. name) . tag ( chatModel. id)
131138 }
132139 }
@@ -135,17 +142,23 @@ struct ExistedChatModelPicker: View {
135142}
136143
137144struct RequestStrategyPicker : View {
138- @AppStorage ( \. requestStrategyId) var requestStrategyId
145+ final class Settings : ObservableObject {
146+ @AppStorage ( \. requestStrategyId) var requestStrategyId
147+ }
148+
149+ @StateObject var settings = Settings ( )
139150
140151 var body : some View {
141- let unknownId : String ? = if RequestStrategyOption ( rawValue: requestStrategyId) == nil {
142- requestStrategyId
152+ let unknownId : String ? =
153+ if RequestStrategyOption ( rawValue: settings. requestStrategyId) == nil
154+ {
155+ settings. requestStrategyId
143156 } else {
144157 nil
145158 }
146159
147160 Picker (
148- selection: $requestStrategyId,
161+ selection: settings . $requestStrategyId,
149162 label: Text ( " Request Strategy " ) ,
150163 content: {
151164 if let unknownId {
0 commit comments