|
1 | 1 | import ActiveApplicationMonitor |
| 2 | +import AppActivator |
2 | 3 | import AsyncAlgorithms |
3 | 4 | import AXNotificationStream |
4 | 5 | import ComposableArchitecture |
@@ -133,6 +134,8 @@ public struct WidgetFeature: ReducerProtocol { |
133 | 134 | @Dependency(\.activeApplicationMonitor) var activeApplicationMonitor |
134 | 135 | @Dependency(\.xcodeInspector) var xcodeInspector |
135 | 136 | @Dependency(\.mainQueue) var mainQueue |
| 137 | + @Dependency(\.activateThisApp) var activateThisApp |
| 138 | + @Dependency(\.activatePreviousActiveApp) var activatePreviousActiveApp |
136 | 139 |
|
137 | 140 | public enum DebounceKey: Hashable { |
138 | 141 | case updateWindowOpacity |
@@ -163,20 +166,26 @@ public struct WidgetFeature: ReducerProtocol { |
163 | 166 | state.panelState.suggestionPanelState.isPanelDisplayed = true |
164 | 167 | state.chatPanelState.isPanelDisplayed = true |
165 | 168 | } |
| 169 | + |
166 | 170 | let isDisplayingContent = state._circularWidgetState.isDisplayingContent |
| 171 | + let hasChat = state.chatPanelState.chatTabGroup.selectedTabInfo != nil |
| 172 | + let hasPromptToCode = state.panelState.sharedPanelState.content |
| 173 | + .promptToCodeGroup.activePromptToCode != nil |
| 174 | + |
167 | 175 | return .run { send in |
168 | 176 | if isDisplayingContent { |
| 177 | + if hasPromptToCode { |
| 178 | + await send(.updateKeyWindow(.sharedPanel)) |
| 179 | + } else if hasChat { |
| 180 | + await send(.updateKeyWindow(.chatPanel)) |
| 181 | + } |
169 | 182 | await send(.chatPanel(.focusActiveChatTab)) |
170 | 183 | } |
171 | | - |
| 184 | + |
172 | 185 | if isDisplayingContent, !(await NSApplication.shared.isActive) { |
173 | | - try await Task.sleep(nanoseconds: 50_000_000) |
174 | | - await NSApplication.shared.activate(ignoringOtherApps: true) |
175 | | - } else if !isDisplayingContent, |
176 | | - let app = xcodeInspector.previousActiveApplication |
177 | | - { |
178 | | - try await Task.sleep(nanoseconds: 20_000_000) |
179 | | - app.runningApplication.activate() |
| 186 | + activateThisApp() |
| 187 | + } else if !isDisplayingContent { |
| 188 | + activatePreviousActiveApp() |
180 | 189 | } |
181 | 190 | } |
182 | 191 |
|
@@ -599,7 +608,7 @@ public struct WidgetFeature: ReducerProtocol { |
599 | 608 | return .none |
600 | 609 |
|
601 | 610 | case let .updateKeyWindow(window): |
602 | | - return .run { _ in |
| 611 | + return .run { send in |
603 | 612 | switch window { |
604 | 613 | case .chatPanel: |
605 | 614 | await windows.chatPanelWindow.makeKeyAndOrderFront(nil) |
|
0 commit comments