Skip to content

Commit 2a36d2e

Browse files
committed
Tweak the behavior of activating the app on chat
1 parent e3bf946 commit 2a36d2e

File tree

7 files changed

+31
-39
lines changed

7 files changed

+31
-39
lines changed

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct GUI {
5555

5656
enum Action {
5757
case start
58-
case openChatPanel(forceDetach: Bool)
58+
case openChatPanel(forceDetach: Bool, activateThisApp: Bool)
5959
case createAndSwitchToChatGPTChatTabIfNeeded
6060
case createAndSwitchToChatTabIfNeededMatching(
6161
check: (any ChatTab) -> Bool,
@@ -138,7 +138,7 @@ struct GUI {
138138
return .none
139139
#endif
140140

141-
case let .openChatPanel(forceDetach):
141+
case let .openChatPanel(forceDetach, activate):
142142
return .run { send in
143143
await send(
144144
.suggestionWidget(
@@ -147,7 +147,9 @@ struct GUI {
147147
)
148148
await send(.suggestionWidget(.updateKeyWindow(.chatPanel)))
149149

150-
activateThisApp()
150+
if activate {
151+
activateThisApp()
152+
}
151153
}
152154

153155
case .createAndSwitchToChatGPTChatTabIfNeeded:
@@ -199,7 +201,7 @@ struct GUI {
199201
let activeTab = chatTabPool.getTab(of: info.id) as? ChatGPTChatTab
200202
{
201203
return .run { send in
202-
await send(.openChatPanel(forceDetach: false))
204+
await send(.openChatPanel(forceDetach: false, activateThisApp: false))
203205
await stopAndHandleCommand(activeTab)
204206
}
205207
}
@@ -211,7 +213,7 @@ struct GUI {
211213
{
212214
state.chatTabGroup.selectedTabId = chatTab.id
213215
return .run { send in
214-
await send(.openChatPanel(forceDetach: false))
216+
await send(.openChatPanel(forceDetach: false, activateThisApp: false))
215217
await stopAndHandleCommand(chatTab)
216218
}
217219
}
@@ -220,7 +222,7 @@ struct GUI {
220222
guard let (chatTab, chatTabInfo) = await chatTabPool.createTab(for: nil)
221223
else { return }
222224
await send(.suggestionWidget(.chatPanel(.appendAndSelectTab(chatTabInfo))))
223-
await send(.openChatPanel(forceDetach: false))
225+
await send(.openChatPanel(forceDetach: false, activateThisApp: false))
224226
if let chatTab = chatTab as? ChatGPTChatTab {
225227
await stopAndHandleCommand(chatTab)
226228
}
@@ -347,7 +349,7 @@ public final class GraphicalUserInterfaceController {
347349
suggestionDependency.onOpenChatClicked = { [weak self] in
348350
Task { [weak self] in
349351
await self?.store.send(.createAndSwitchToChatGPTChatTabIfNeeded).finish()
350-
self?.store.send(.openChatPanel(forceDetach: false))
352+
self?.store.send(.openChatPanel(forceDetach: false, activateThisApp: true))
351353
}
352354
}
353355
suggestionDependency.onCustomCommandClicked = { command in

Core/Sources/Service/GlobalShortcutManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class GlobalShortcutManager {
2828
!guiController.store.state.suggestionWidgetState.chatPanelState.isPanelDisplayed,
2929
UserDefaults.shared.value(for: \.showHideWidgetShortcutGlobally)
3030
{
31-
guiController.store.send(.openChatPanel(forceDetach: true))
31+
guiController.store.send(.openChatPanel(forceDetach: true, activateThisApp: true))
3232
} else {
3333
guiController.store.send(.toggleWidgetsHotkeyPressed)
3434
}

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,16 @@ struct PseudoCommandHandler: CommandHandler {
332332
await filespace.reset()
333333
}
334334

335-
func openChat(forceDetach: Bool) {
335+
func openChat(forceDetach: Bool, activateThisApp: Bool = true) {
336336
switch UserDefaults.shared.value(for: \.openChatMode) {
337337
case .chatPanel:
338338
Task { @MainActor in
339339
let store = Service.shared.guiController.store
340340
await store.send(.createAndSwitchToChatGPTChatTabIfNeeded).finish()
341-
store.send(.openChatPanel(forceDetach: forceDetach))
341+
store.send(.openChatPanel(
342+
forceDetach: forceDetach,
343+
activateThisApp: activateThisApp
344+
))
342345
}
343346
case .browser:
344347
let urlString = UserDefaults.shared.value(for: \.openChatInBrowserURL)
@@ -375,7 +378,10 @@ struct PseudoCommandHandler: CommandHandler {
375378
},
376379
kind: .init(BrowserChatTab.urlChatBuilder(url: url))
377380
)).finish()
378-
store.send(.openChatPanel(forceDetach: forceDetach))
381+
store.send(.openChatPanel(
382+
forceDetach: forceDetach,
383+
activateThisApp: activateThisApp
384+
))
379385
}
380386
#endif
381387
} else {
@@ -393,13 +399,17 @@ struct PseudoCommandHandler: CommandHandler {
393399
kind: .init(CodeiumChatTab.defaultChatBuilder())
394400
)
395401
).finish()
396-
store.send(.openChatPanel(forceDetach: forceDetach))
402+
store.send(.openChatPanel(
403+
forceDetach: forceDetach,
404+
activateThisApp: activateThisApp
405+
))
397406
}
398407
}
399408
}
400409

410+
@MainActor
401411
func sendChatMessage(_ message: String) async {
402-
let store = await Service.shared.guiController.store
412+
let store = Service.shared.guiController.store
403413
await store.send(.sendCustomCommandToActiveChat(CustomCommand(
404414
commandId: "",
405415
name: "",

Core/Sources/Service/SuggestionPresenter/PresentInWindowSuggestionPresenter.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,10 @@ struct PresentInWindowSuggestionPresenter {
4242
}
4343
}
4444

45-
func closeChatRoom(fileURL: URL) {
46-
Task { @MainActor in
47-
let controller = Service.shared.guiController.widgetController
48-
controller.closeChatRoom()
49-
}
50-
}
51-
5245
func presentChatRoom(fileURL: URL) {
5346
Task { @MainActor in
54-
let controller = Service.shared.guiController.widgetController
55-
controller.presentChatRoom()
47+
let controller = Service.shared.guiController
48+
controller.store.send(.openChatPanel(forceDetach: false, activateThisApp: true))
5649
}
5750
}
5851
}

Core/Sources/SuggestionWidget/FeatureReducers/ChatPanelFeature.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public struct ChatPanelFeature {
166166
.chatPanelWindow
167167
.centerInActiveSpaceIfNeeded()
168168
}
169-
activateExtensionService()
170169
await send(.focusActiveChatTab)
171170
}
172171

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,5 @@ public extension SuggestionWidgetController {
7070
func presentError(_ errorDescription: String) {
7171
store.send(.toastPanel(.toast(.toast(errorDescription, .error, nil))))
7272
}
73-
74-
func presentChatRoom() {
75-
store.send(.chatPanel(.presentChatPanel(forceDetach: false)))
76-
}
77-
78-
func presentDetachedGlobalChat() {
79-
store.send(.chatPanel(.presentChatPanel(forceDetach: true)))
80-
}
81-
82-
func closeChatRoom() {
83-
// store.send(.chatPanel(.closeChatPanel))
84-
}
8573
}
8674

Tool/Sources/CommandHandler/CommandHandler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public protocol CommandHandler {
1919

2020
// MARK: Chat
2121

22-
func openChat(forceDetach: Bool)
22+
func openChat(forceDetach: Bool, activateThisApp: Bool)
2323
func sendChatMessage(_ message: String) async
2424

2525
// MARK: Prompt to Code
@@ -86,8 +86,8 @@ public final class UniversalCommandHandler: CommandHandler {
8686
await commandHandler.generateRealtimeSuggestions(sourceEditor: sourceEditor)
8787
}
8888

89-
public func openChat(forceDetach: Bool) {
90-
commandHandler.openChat(forceDetach: forceDetach)
89+
public func openChat(forceDetach: Bool, activateThisApp: Bool) {
90+
commandHandler.openChat(forceDetach: forceDetach, activateThisApp: activateThisApp)
9191
}
9292

9393
public func sendChatMessage(_ message: String) async {
@@ -115,7 +115,7 @@ struct NoopCommandHandler: CommandHandler {
115115
func acceptSuggestion() async {}
116116
func dismissSuggestion() async {}
117117
func generateRealtimeSuggestions(sourceEditor: SourceEditor?) async {}
118-
func openChat(forceDetach: Bool) {}
118+
func openChat(forceDetach: Bool, activateThisApp: Bool) {}
119119
func sendChatMessage(_: String) async {}
120120
func acceptPromptToCode() async {}
121121
func handleCustomCommand(_: CustomCommand) async {}

0 commit comments

Comments
 (0)