-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathSuggestionWidgetController.swift
More file actions
118 lines (96 loc) · 3.15 KB
/
SuggestionWidgetController.swift
File metadata and controls
118 lines (96 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import ActiveApplicationMonitor
import AppKit
import AsyncAlgorithms
import ChatTab
import Combine
import ComposableArchitecture
import Preferences
import SwiftUI
import UserDefaultsObserver
import XcodeInspector
import SuggestionBasic
@MainActor
public final class SuggestionWidgetController: NSObject {
let store: StoreOf<WidgetFeature>
let chatTabPool: ChatTabPool
let windowsController: WidgetWindowsController
private var cancellable = Set<AnyCancellable>()
public let dependency: SuggestionWidgetControllerDependency
public init(
store: StoreOf<WidgetFeature>,
chatTabPool: ChatTabPool,
dependency: SuggestionWidgetControllerDependency
) {
self.dependency = dependency
self.store = store
self.chatTabPool = chatTabPool
windowsController = .init(store: store, chatTabPool: chatTabPool)
super.init()
if ProcessInfo.processInfo.environment["IS_UNIT_TEST"] == "YES" { return }
dependency.windowsController = windowsController
store.send(.startup)
Task {
await windowsController.start()
}
}
}
// MARK: - Handle Events
public extension SuggestionWidgetController {
func suggestCode() {
store.send(.panel(.presentSuggestion))
}
func suggestNESCode() {
store.send(.panel(.presentNESSuggestion))
}
func expandSuggestion() {
store.withState { state in
if state.panelState.content.suggestion != nil {
store.send(.panel(.expandSuggestion))
}
}
}
func discardSuggestion() {
store.withState { state in
if state.panelState.content.suggestion != nil {
store.send(.panel(.discardSuggestion))
}
}
}
func discardNESSuggestion() {
store.withState { state in
if state.panelState.nesContent != nil {
store.send(.panel(.discardNESSuggestion))
}
}
}
#warning("TODO: Make a progress controller that doesn't use TCA.")
func markAsProcessing(_ isProcessing: Bool) {
store.withState { state in
if isProcessing, !state.circularWidgetState.isProcessing {
store.send(.circularWidget(.markIsProcessing))
} else if !isProcessing, state.circularWidgetState.isProcessing {
store.send(.circularWidget(.endIsProcessing))
}
}
}
func presentError(_ errorDescription: String) {
store.send(.toastPanel(.toast(.toast(errorDescription, .error, nil))))
}
func presentChatRoom() {
store.send(.chatPanel(.presentChatPanel(forceDetach: false)))
}
func presentDetachedGlobalChat() {
store.send(.chatPanel(.presentChatPanel(forceDetach: true)))
}
func closeChatRoom() {
// store.send(.chatPanel(.closeChatPanel))
}
}
extension SuggestionWidgetController {
public func presentWarning(message: String, url: String?) {
store.send(.panel(.presentWarning(message: message, url: url)))
}
public func dismissWarning() {
store.send(.panel(.dismissWarning))
}
}