Skip to content

Commit a23c504

Browse files
committed
Activate Xcode when needed
1 parent be8e0ee commit a23c504

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

Core/Sources/Service/GUI/PromptToCodeProvider+Service.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ActiveApplicationMonitor
12
import Combine
23
import PromptToCodeService
34
import SuggestionWidget
@@ -58,6 +59,9 @@ extension PromptToCodeProvider {
5859
Task { @ServiceActor in
5960
let handler = PseudoCommandHandler()
6061
await handler.acceptSuggestion()
62+
if let app = ActiveApplicationMonitor.previousActiveApplication, app.isXcode {
63+
app.activate()
64+
}
6165
}
6266
}
6367

@@ -74,3 +78,4 @@ extension PromptToCodeProvider {
7478
}
7579
}
7680
}
81+

Core/Sources/Service/GUI/WidgetDataSource.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,22 @@ extension WidgetDataSource: SuggestionWidgetDataSource {
173173
Task { @ServiceActor in
174174
let handler = PseudoCommandHandler()
175175
await handler.rejectSuggestions()
176+
if let app = ActiveApplicationMonitor.previousActiveApplication,
177+
app.isXcode
178+
{
179+
app.activate()
180+
}
176181
}
177182
},
178183
onAcceptSuggestionTapped: {
179184
Task { @ServiceActor in
180185
let handler = PseudoCommandHandler()
181186
await handler.acceptSuggestion()
187+
if let app = ActiveApplicationMonitor.previousActiveApplication,
188+
app.isXcode
189+
{
190+
app.activate()
191+
}
182192
}
183193
}
184194
)

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ActiveApplicationMonitor
12
import AppKit
23
import SwiftUI
34

@@ -9,7 +10,7 @@ final class ChatWindowViewModel: ObservableObject {
910
@Published var colorScheme: ColorScheme
1011
@Published var isPanelDisplayed = false
1112
@Published var chatPanelInASeparateWindow = false
12-
13+
1314
public init(chat: ChatProvider? = nil, colorScheme: ColorScheme = .dark) {
1415
self.chat = chat
1516
self.colorScheme = colorScheme
@@ -26,6 +27,11 @@ struct ChatWindowView: View {
2627
.background {
2728
Button(action: {
2829
viewModel.isPanelDisplayed = false
30+
if let app = ActiveApplicationMonitor.previousActiveApplication,
31+
app.isXcode
32+
{
33+
app.activate()
34+
}
2935
}) {
3036
EmptyView()
3137
}
@@ -38,3 +44,4 @@ struct ChatWindowView: View {
3844
.preferredColorScheme(viewModel.colorScheme)
3945
}
4046
}
47+

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ActiveApplicationMonitor
12
import Environment
23
import Preferences
34
import SuggestionModel
@@ -26,15 +27,24 @@ struct WidgetView: View {
2627
Circle().fill(isHovering ? .white.opacity(0.8) : .white.opacity(0.3))
2728
.onTapGesture {
2829
withAnimation(.easeInOut(duration: 0.2)) {
29-
let isDisplayed = {
30+
let wasDisplayed = {
3031
if panelViewModel.isPanelDisplayed,
3132
panelViewModel.content != nil { return true }
3233
if chatWindowViewModel.isPanelDisplayed,
3334
chatWindowViewModel.chat != nil { return true }
3435
return false
3536
}()
36-
panelViewModel.isPanelDisplayed = !isDisplayed
37-
chatWindowViewModel.isPanelDisplayed = !isDisplayed
37+
panelViewModel.isPanelDisplayed = !wasDisplayed
38+
chatWindowViewModel.isPanelDisplayed = !wasDisplayed
39+
let isDisplayed = !wasDisplayed
40+
41+
if !isDisplayed {
42+
if let app = ActiveApplicationMonitor.previousActiveApplication,
43+
app.isXcode
44+
{
45+
app.activate()
46+
}
47+
}
3848
}
3949
}
4050
.overlay {

0 commit comments

Comments
 (0)