Skip to content

Commit c8d0c50

Browse files
committed
Activate Xcode when closing chat and prompt to code
1 parent cea9212 commit c8d0c50

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Core/Sources/ActiveApplicationMonitor/ActiveApplicationMonitor.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ public final class ActiveApplicationMonitor {
44
static let shared = ActiveApplicationMonitor()
55
var latestXcode: NSRunningApplication? = NSWorkspace.shared.runningApplications
66
.first(where: \.isXcode)
7+
var previousApp: NSRunningApplication?
78
var activeApplication = NSWorkspace.shared.runningApplications.first(where: \.isActive) {
89
didSet {
910
if activeApplication?.isXcode ?? false {
1011
latestXcode = activeApplication
1112
}
13+
previousApp = oldValue
1214
}
1315
}
1416

@@ -35,6 +37,8 @@ public final class ActiveApplicationMonitor {
3537
}
3638

3739
public static var activeApplication: NSRunningApplication? { shared.activeApplication }
40+
41+
public static var previousActiveApplication: NSRunningApplication? { shared.previousApp }
3842

3943
public static var activeXcode: NSRunningApplication? {
4044
if activeApplication?.isXcode ?? false {
@@ -77,3 +81,4 @@ public final class ActiveApplicationMonitor {
7781
public extension NSRunningApplication {
7882
var isXcode: Bool { bundleIdentifier == "com.apple.dt.Xcode" }
7983
}
84+

Core/Sources/Service/GUI/WidgetDataSource.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import ActiveApplicationMonitor
12
import ChatService
2-
import SuggestionModel
3-
import GitHubCopilotService
43
import Foundation
4+
import GitHubCopilotService
55
import OpenAIService
66
import PromptToCodeService
7+
import SuggestionModel
78
import SuggestionWidget
89

910
@ServiceActor
@@ -52,6 +53,9 @@ final class WidgetDataSource {
5253
}
5354
let presenter = PresentInWindowSuggestionPresenter()
5455
presenter.closeChatRoom(fileURL: url)
56+
if let app = ActiveApplicationMonitor.previousActiveApplication, app.isXcode {
57+
app.activate()
58+
}
5559
},
5660
onSwitchContext: { [weak self] in
5761
let useGlobalChat = UserDefaults.shared.value(for: \.useGlobalChat)
@@ -114,6 +118,9 @@ final class WidgetDataSource {
114118
self?.removePromptToCode(for: url)
115119
let presenter = PresentInWindowSuggestionPresenter()
116120
presenter.closePromptToCode(fileURL: url)
121+
if let app = ActiveApplicationMonitor.previousActiveApplication, app.isXcode {
122+
app.activate()
123+
}
117124
}
118125
)
119126
return PromptToCode(promptToCodeService: service, provider: provider)
@@ -199,3 +206,4 @@ extension WidgetDataSource: SuggestionWidgetDataSource {
199206
return promptToCodes[url]?.provider
200207
}
201208
}
209+

0 commit comments

Comments
 (0)