Skip to content

Commit 07b1c96

Browse files
committed
Setup promptToCodeAcceptHandler
1 parent a5e0935 commit 07b1c96

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ActiveApplicationMonitor
12
import AppKit
23
import ChatGPTChatTab
34
import ChatTab
@@ -224,6 +225,19 @@ public final class GraphicalUserInterfaceController {
224225
dependencies.suggestionWidgetUserDefaultsObservers = .init()
225226
dependencies.chatTabPool = chatTabPool
226227
dependencies.chatTabBuilderCollection = ChatTabFactory.chatTabBuilderCollection
228+
dependencies.promptToCodeAcceptHandler = { promptToCode in
229+
Task {
230+
let handler = PseudoCommandHandler()
231+
await handler.acceptPromptToCode()
232+
if let app = ActiveApplicationMonitor.shared.previousApp,
233+
app.isXcode,
234+
!promptToCode.isContinuous
235+
{
236+
try await Task.sleep(nanoseconds: 200_000_000)
237+
app.activate()
238+
}
239+
}
240+
}
227241

228242
#if canImport(ChatTabPersistent) && canImport(ProChatTabs)
229243
dependencies.restoreChatTabInPool = {

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import Foundation
55
import PromptToCodeService
66
import SuggestionModel
77

8-
struct PromptToCodeAcceptHandlerDependencyKey: DependencyKey {
9-
static let liveValue: () -> Void = {}
10-
static let previewValue: () -> Void = { print("Accept Prompt to Code") }
8+
public struct PromptToCodeAcceptHandlerDependencyKey: DependencyKey {
9+
public static let liveValue: (PromptToCode.State) -> Void = { _ in
10+
assertionFailure("Please provide a handler")
11+
}
12+
13+
public static let previewValue: (PromptToCode.State) -> Void = { _ in
14+
print("Accept Prompt to Code")
15+
}
1116
}
1217

13-
extension DependencyValues {
14-
var promptToCodeAcceptHandler: () -> Void {
18+
public extension DependencyValues {
19+
var promptToCodeAcceptHandler: (PromptToCode.State) -> Void {
1520
get { self[PromptToCodeAcceptHandlerDependencyKey.self] }
1621
set { self[PromptToCodeAcceptHandlerDependencyKey.self] = newValue }
1722
}
@@ -228,7 +233,7 @@ public struct PromptToCode: ReducerProtocol {
228233
return .none
229234

230235
case .acceptButtonTapped:
231-
promptToCodeAcceptHandler()
236+
promptToCodeAcceptHandler(state)
232237
return .none
233238

234239
case .copyCodeButtonTapped:

0 commit comments

Comments
 (0)