forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostApp.swift
More file actions
108 lines (88 loc) · 2.76 KB
/
HostApp.swift
File metadata and controls
108 lines (88 loc) · 2.76 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
import Client
import ComposableArchitecture
import Foundation
import KeyboardShortcuts
#if canImport(LicenseManagement)
import ProHostApp
#endif
extension KeyboardShortcuts.Name {
static let showHideWidget = Self("ShowHideWidget")
}
@Reducer
struct HostApp {
@ObservableState
struct State: Equatable {
var general = General.State()
var chatModelManagement = ChatModelManagement.State()
var embeddingModelManagement = EmbeddingModelManagement.State()
}
enum Action {
case appear
case general(General.Action)
case chatModelManagement(ChatModelManagement.Action)
case embeddingModelManagement(EmbeddingModelManagement.Action)
}
@Dependency(\.toast) var toast
init() {
KeyboardShortcuts.userDefaults = .shared
}
var body: some ReducerOf<Self> {
Scope(state: \.general, action: \.general) {
General()
}
Scope(state: \.chatModelManagement, action: \.chatModelManagement) {
ChatModelManagement()
}
Scope(state: \.embeddingModelManagement, action: \.embeddingModelManagement) {
EmbeddingModelManagement()
}
Reduce { _, action in
switch action {
case .appear:
#if canImport(ProHostApp)
ProHostApp.start()
#endif
return .none
case .general:
return .none
case .chatModelManagement:
return .none
case .embeddingModelManagement:
return .none
}
}
}
}
import Dependencies
import Keychain
import Preferences
struct UserDefaultsDependencyKey: DependencyKey {
static var liveValue: UserDefaultsType = UserDefaults.shared
static var previewValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppPreview")!
it.removePersistentDomain(forName: "HostAppPreview")
return it
}()
static var testValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppTest")!
it.removePersistentDomain(forName: "HostAppTest")
return it
}()
}
extension DependencyValues {
var userDefaults: UserDefaultsType {
get { self[UserDefaultsDependencyKey.self] }
set { self[UserDefaultsDependencyKey.self] = newValue }
}
}
struct APIKeyKeychainDependencyKey: DependencyKey {
static var liveValue: KeychainType = Keychain.apiKey
static var previewValue: KeychainType = FakeKeyChain()
static var testValue: KeychainType = FakeKeyChain()
}
extension DependencyValues {
var apiKeyKeychain: KeychainType {
get { self[APIKeyKeychainDependencyKey.self] }
set { self[APIKeyKeychainDependencyKey.self] = newValue }
}
}