@@ -187,31 +187,26 @@ struct GUI {
187187 }
188188
189189 case let . sendCustomCommandToActiveChat( command) :
190- @Sendable func stopAndHandleCommand( _ tab: ChatGPTChatTab ) async {
191- if tab. service. isReceivingMessage {
192- await tab. service. stopReceivingMessage ( )
193- }
194- try ? await tab. service. handleCustomCommand ( command)
195- }
196-
197190 if let info = state. chatTabGroup. selectedTabInfo,
198- let activeTab = chatTabPool. getTab ( of: info. id) as? ChatGPTChatTab
191+ let tab = chatTabPool. getTab ( of: info. id) ,
192+ tab. handleCustomCommand ( command)
199193 {
200194 return . run { send in
201195 await send ( . openChatPanel( forceDetach: false , activateThisApp: false ) )
202- await stopAndHandleCommand ( activeTab)
203196 }
204197 }
205198
206- if let info = state. chatTabGroup. tabInfo. first ( where: {
207- chatTabPool. getTab ( of: $0. id) is ChatGPTChatTab
208- } ) ,
209- let chatTab = chatTabPool. getTab ( of: info. id) as? ChatGPTChatTab
210- {
211- state. chatTabGroup. selectedTabId = chatTab. id
212- return . run { send in
213- await send ( . openChatPanel( forceDetach: false , activateThisApp: false ) )
214- await stopAndHandleCommand ( chatTab)
199+ for info in state. chatTabGroup. tabInfo {
200+ if let chatTab = chatTabPool. getTab ( of: info. id) ,
201+ chatTab. handleCustomCommand ( command)
202+ {
203+ state. chatTabGroup. selectedTabId = chatTab. id
204+ return . run { send in
205+ await send ( . openChatPanel(
206+ forceDetach: false ,
207+ activateThisApp: false
208+ ) )
209+ }
215210 }
216211 }
217212
@@ -220,9 +215,7 @@ struct GUI {
220215 else { return }
221216 await send ( . suggestionWidget( . chatPanel( . appendAndSelectTab( chatTabInfo) ) ) )
222217 await send ( . openChatPanel( forceDetach: false , activateThisApp: false ) )
223- if let chatTab = chatTab as? ChatGPTChatTab {
224- await stopAndHandleCommand ( chatTab)
225- }
218+ _ = chatTab. handleCustomCommand ( command)
226219 }
227220
228221 case . toggleWidgetsHotkeyPressed:
0 commit comments