forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicalUserInterfaceController.swift.swift
More file actions
38 lines (36 loc) · 1.39 KB
/
GraphicalUserInterfaceController.swift.swift
File metadata and controls
38 lines (36 loc) · 1.39 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
import AppKit
import Environment
import SuggestionWidget
@MainActor
public final class GraphicalUserInterfaceController {
public nonisolated static let shared = GraphicalUserInterfaceController()
nonisolated let suggestionWidget = SuggestionWidgetController()
private nonisolated init() {
Task { @MainActor in
suggestionWidget.dataSource = WidgetDataSource.shared
suggestionWidget.onOpenChatClicked = { [weak self] in
Task {
let uri = try await Environment.fetchFocusedElementURI()
let dataSource = WidgetDataSource.shared
await dataSource.createChatIfNeeded(for: uri)
self?.suggestionWidget.presentChatRoom(fileURL: uri)
}
}
suggestionWidget.onCustomCommandClicked = { command in
Task {
let commandHandler = PseudoCommandHandler()
await commandHandler.handleCustomCommand(command)
}
}
}
}
public func openGlobalChat() {
UserDefaults.shared.set(true, for: \.useGlobalChat)
let dataSource = WidgetDataSource.shared
let fakeFileURL = URL(fileURLWithPath: "/")
Task {
await dataSource.createChatIfNeeded(for: fakeFileURL)
suggestionWidget.presentDetachedGlobalChat()
}
}
}