11import ActiveApplicationMonitor
2+ import AppActivator
23import AppKit
34import ChatGPTChatTab
45import ChatTab
56import ComposableArchitecture
67import Dependencies
78import Environment
89import Preferences
10+ import SuggestionModel
911import SuggestionWidget
1012
1113#if canImport(ProChatTabs)
@@ -54,6 +56,7 @@ struct GUI: ReducerProtocol {
5456 case openChatPanel( forceDetach: Bool )
5557 case createChatGPTChatTabIfNeeded
5658 case sendCustomCommandToActiveChat( CustomCommand )
59+ case toggleWidgetsHotkeyPressed
5760
5861 case suggestionWidget( WidgetFeature . Action )
5962
@@ -66,7 +69,8 @@ struct GUI: ReducerProtocol {
6669 #endif
6770 }
6871
69- @Dependency ( \. chatTabPool) var chatTabPool : ChatTabPool
72+ @Dependency ( \. chatTabPool) var chatTabPool
73+ @Dependency ( \. activateThisApp) var activateThisApp
7074
7175 public enum Debounce : Hashable {
7276 case updateChatTabOrder
@@ -135,6 +139,9 @@ struct GUI: ReducerProtocol {
135139 . chatPanel( . presentChatPanel( forceDetach: forceDetach) )
136140 )
137141 )
142+ await send ( . suggestionWidget( . updateKeyWindow( . chatPanel) ) )
143+
144+ activateThisApp ( )
138145 }
139146
140147 case . createChatGPTChatTabIfNeeded:
@@ -192,6 +199,11 @@ struct GUI: ReducerProtocol {
192199 }
193200 }
194201
202+ case . toggleWidgetsHotkeyPressed:
203+ return . run { send in
204+ await send ( . suggestionWidget( . circularWidget( . widgetClicked) ) )
205+ }
206+
195207 case let . suggestionWidget( . chatPanel( . chatTab( id, . tabContentUpdated) ) ) :
196208 #if canImport(ChatTabPersistent)
197209 // when a tab is updated, persist it.
@@ -262,12 +274,10 @@ public final class GraphicalUserInterfaceController {
262274 Task {
263275 let handler = PseudoCommandHandler ( )
264276 await handler. acceptPromptToCode ( )
265- if let app = ActiveApplicationMonitor . shared. previousApp,
266- app. isXcode,
267- !promptToCode. isContinuous
268- {
269- try await Task . sleep ( nanoseconds: 200_000_000 )
270- app. activate ( )
277+ if !promptToCode. isContinuous {
278+ NSWorkspace . activatePreviousActiveXcode ( )
279+ } else {
280+ NSWorkspace . activateThisApp ( )
271281 }
272282 }
273283 }
0 commit comments