Skip to content

Commit 653d128

Browse files
committed
Migrate Service to latest TCA
1 parent 121d173 commit 653d128

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import ProChatTabs
1717
import ChatTabPersistent
1818
#endif
1919

20-
struct GUI: ReducerProtocol {
20+
@Reducer
21+
struct GUI {
22+
@ObservableState
2123
struct State: Equatable {
2224
var suggestionWidgetState = WidgetFeature.State()
2325

@@ -75,15 +77,15 @@ struct GUI: ReducerProtocol {
7577
case updateChatTabOrder
7678
}
7779

78-
var body: some ReducerProtocol<State, Action> {
80+
var body: some ReducerOf<Self> {
7981
CombineReducers {
80-
Scope(state: \.suggestionWidgetState, action: /Action.suggestionWidget) {
82+
Scope(state: \.suggestionWidgetState, action: \.suggestionWidget) {
8183
WidgetFeature()
8284
}
8385

8486
Scope(
8587
state: \.chatTabGroup,
86-
action: /Action.suggestionWidget .. /WidgetFeature.Action.chatPanel
88+
action: \.suggestionWidget.chatPanel
8789
) {
8890
Reduce { _, action in
8991
switch action {
@@ -115,7 +117,7 @@ struct GUI: ReducerProtocol {
115117
}
116118

117119
#if canImport(ChatTabPersistent)
118-
Scope(state: \.persistentState, action: /Action.persistent) {
120+
Scope(state: \.persistentState, action: \.persistent) {
119121
ChatTabPersistent()
120122
}
121123
#endif
@@ -251,10 +253,9 @@ struct GUI: ReducerProtocol {
251253

252254
@MainActor
253255
public final class GraphicalUserInterfaceController {
254-
private let store: StoreOf<GUI>
256+
let store: StoreOf<GUI>
255257
let widgetController: SuggestionWidgetController
256258
let widgetDataSource: WidgetDataSource
257-
let viewStore: ViewStoreOf<GUI>
258259
let chatTabPool: ChatTabPool
259260

260261
class WeakStoreHolder {
@@ -289,18 +290,17 @@ public final class GraphicalUserInterfaceController {
289290
}
290291
let store = StoreOf<GUI>(
291292
initialState: .init(),
292-
reducer: GUI(),
293-
prepareDependencies: setupDependency
293+
reducer: { GUI() },
294+
withDependencies: setupDependency
294295
)
295296
self.store = store
296297
self.chatTabPool = chatTabPool
297-
viewStore = ViewStore(store)
298298
widgetDataSource = .init()
299299

300300
widgetController = SuggestionWidgetController(
301301
store: store.scope(
302302
state: \.suggestionWidgetState,
303-
action: GUI.Action.suggestionWidget
303+
action: \.suggestionWidget
304304
),
305305
chatTabPool: chatTabPool,
306306
dependency: suggestionDependency
@@ -309,8 +309,7 @@ public final class GraphicalUserInterfaceController {
309309
chatTabPool.createStore = { id in
310310
store.scope(
311311
state: { state in
312-
state.chatTabGroup.tabInfo[id: id]
313-
?? .init(id: id, title: "")
312+
state.chatTabGroup.tabInfo[id: id] ?? .init(id: id, title: "")
314313
},
315314
action: { childAction in
316315
.suggestionWidget(.chatPanel(.chatTab(id: id, action: childAction)))
@@ -321,8 +320,8 @@ public final class GraphicalUserInterfaceController {
321320
suggestionDependency.suggestionWidgetDataSource = widgetDataSource
322321
suggestionDependency.onOpenChatClicked = { [weak self] in
323322
Task { [weak self] in
324-
await self?.viewStore.send(.createChatGPTChatTabIfNeeded).finish()
325-
self?.viewStore.send(.openChatPanel(forceDetach: false))
323+
await self?.store.send(.createChatGPTChatTabIfNeeded).finish()
324+
self?.store.send(.openChatPanel(forceDetach: false))
326325
}
327326
}
328327
suggestionDependency.onCustomCommandClicked = { command in
@@ -339,8 +338,8 @@ public final class GraphicalUserInterfaceController {
339338

340339
public func openGlobalChat() {
341340
Task {
342-
await self.viewStore.send(.createChatGPTChatTabIfNeeded).finish()
343-
viewStore.send(.openChatPanel(forceDetach: true))
341+
await self.store.send(.createChatGPTChatTabIfNeeded).finish()
342+
store.send(.openChatPanel(forceDetach: true))
344343
}
345344
}
346345
}

Core/Sources/Service/GlobalShortcutManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ final class GlobalShortcutManager {
2525
let isXCodeActive = XcodeInspector.shared.activeXcode != nil
2626

2727
if !isXCodeActive,
28-
!guiController.viewStore.state.suggestionWidgetState.chatPanelState.isPanelDisplayed,
28+
!guiController.store.state.suggestionWidgetState.chatPanelState.isPanelDisplayed,
2929
UserDefaults.shared.value(for: \.showHideWidgetShortcutGlobally)
3030
{
31-
guiController.viewStore.send(.openChatPanel(forceDetach: true))
31+
guiController.store.send(.openChatPanel(forceDetach: true))
3232
} else {
33-
guiController.viewStore.send(.toggleWidgetsHotkeyPressed)
33+
guiController.store.send(.toggleWidgetsHotkeyPressed)
3434
}
3535
}
3636

Core/Sources/Service/ScheduledCleaner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public final class ScheduledCleaner {
5252
if workspace.isExpired, workspaceInfos[.url(url)] == nil {
5353
Logger.service.info("Remove idle workspace")
5454
_ = await Task { @MainActor in
55-
service.guiController.viewStore.send(
55+
service.guiController.store.send(
5656
.promptToCodeGroup(.discardExpiredPromptToCode(documentURLs: Array(
5757
workspace.filespaces.keys
5858
)))
@@ -72,7 +72,7 @@ public final class ScheduledCleaner {
7272
) {
7373
Logger.service.info("Remove idle filespace")
7474
_ = await Task { @MainActor in
75-
service.guiController.viewStore.send(
75+
service.guiController.store.send(
7676
.promptToCodeGroup(.discardExpiredPromptToCode(documentURLs: [url]))
7777
)
7878
}.result

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
178178
var cursorPosition = editor.cursorPosition
179179
var extraInfo = SuggestionInjector.ExtraInfo()
180180

181-
let viewStore = Service.shared.guiController.viewStore
181+
let store = Service.shared.guiController.store
182182

183-
if let promptToCode = viewStore.state.promptToCodeGroup.activePromptToCode {
183+
if let promptToCode = store.state.promptToCodeGroup.activePromptToCode {
184184
if promptToCode.isAttachedToSelectionRange, promptToCode.documentURL != fileURL {
185185
return nil
186186
}
@@ -214,13 +214,13 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
214214
)
215215

216216
_ = await Task { @MainActor [cursorPosition] in
217-
viewStore.send(
217+
store.send(
218218
.promptToCodeGroup(.updatePromptToCodeRange(
219219
id: promptToCode.id,
220220
range: .init(start: range.start, end: cursorPosition)
221221
))
222222
)
223-
viewStore.send(
223+
store.send(
224224
.promptToCodeGroup(.discardAcceptedPromptToCodeIfNotContinuous(
225225
id: promptToCode.id
226226
))
@@ -264,9 +264,9 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
264264

265265
func chatWithSelection(editor: EditorContent) async throws -> UpdatedContent? {
266266
Task { @MainActor in
267-
let viewStore = Service.shared.guiController.viewStore
268-
viewStore.send(.createChatGPTChatTabIfNeeded)
269-
viewStore.send(.openChatPanel(forceDetach: false))
267+
let store = Service.shared.guiController.store
268+
store.send(.createChatGPTChatTabIfNeeded)
269+
store.send(.openChatPanel(forceDetach: false))
270270
}
271271
return nil
272272
}
@@ -314,7 +314,7 @@ extension WindowBaseCommandHandler {
314314
switch command.feature {
315315
case .chatWithSelection, .customChat:
316316
Task { @MainActor in
317-
Service.shared.guiController.viewStore
317+
Service.shared.guiController.store
318318
.send(.sendCustomCommandToActiveChat(command))
319319
}
320320
case let .promptToCode(extraSystemPrompt, prompt, continuousMode, generateDescription):
@@ -397,7 +397,7 @@ extension WindowBaseCommandHandler {
397397
)
398398
}() as (String, CursorRange)
399399

400-
let viewStore = Service.shared.guiController.viewStore
400+
let store = Service.shared.guiController.store
401401

402402
let customCommandTemplateProcessor = CustomCommandTemplateProcessor()
403403

@@ -415,7 +415,7 @@ extension WindowBaseCommandHandler {
415415

416416
_ = await Task { @MainActor in
417417
// if there is already a prompt to code presenting, we should not present another one
418-
viewStore.send(.promptToCodeGroup(.activateOrCreatePromptToCode(.init(
418+
store.send(.promptToCodeGroup(.activateOrCreatePromptToCode(.init(
419419
code: code,
420420
selectionRange: selection,
421421
language: codeLanguage,

0 commit comments

Comments
 (0)